Skip to content

Commit

Permalink
fix(feed): remove location cache (#1297)
Browse files Browse the repository at this point in the history
* feat(feed): support location in cosmos

Signed-off-by: Norman Meier <[email protected]>

* fix: remove feed cache

Signed-off-by: Norman Meier <[email protected]>

---------

Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz authored Oct 8, 2024
1 parent fdc5bf3 commit 5b0c900
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions go/pkg/feed/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ func (s *FeedService) PostsWithLocation(ctx context.Context, data *feedpb.PostsW
}
func (s *FeedService) getPostsWithLocationFilter(networkID string, locationFilter *locationQueryData) ([]indexerdb.Post, error) {
posts := make([]indexerdb.Post, 0)
cachekey := fmt.Sprintf("%s/%s", networkID, locationFilter.cacheKey())
data, ok := s.cache.Get(cachekey)
if ok {
return data.([]indexerdb.Post), nil
}

query := s.conf.IndexerDB.Model(&indexerdb.Post{})
if networkID != "" {
query = query.Where("network_id = ?", networkID)
Expand All @@ -251,17 +247,10 @@ func (s *FeedService) getPostsWithLocationFilter(networkID string, locationFilte
return nil, err
}

s.cache.SetWithTTL(cachekey, posts, 0, time.Minute*5)

return posts, nil
}

func (s *FeedService) getPostsCountWithLocationFilter(networkID string, locationFilter *locationQueryData) (int64, error) {
cachekey := fmt.Sprintf("%s/%s", networkID, locationFilter.countCacheKey())
data, ok := s.cache.Get(cachekey)
if ok {
return data.(int64), nil
}
var totalPost int64

query := s.conf.IndexerDB.Model(&indexerdb.Post{})
Expand All @@ -273,8 +262,6 @@ func (s *FeedService) getPostsCountWithLocationFilter(networkID string, location
return 0, err
}

s.cache.SetWithTTL(cachekey, totalPost, 0, time.Minute*5)

return totalPost, nil
}

Expand Down Expand Up @@ -356,12 +343,6 @@ func (s *FeedService) loadDetailedPosts(data *feedpb.PostsWithLocationRequest, l

return res, nil
}
func (data *locationQueryData) countCacheKey() string {
return "count_" + data.cacheKey()
}
func (data *locationQueryData) cacheKey() string {
return fmt.Sprintf("%d_%d_%d_%d", data.N, data.S, data.W, data.E)
}

func locationFilter(data *feedpb.PostsWithLocationRequest) *locationQueryData {
return &locationQueryData{
Expand Down

0 comments on commit 5b0c900

Please sign in to comment.