aboutsummaryrefslogtreecommitdiff
path: root/fetchers/cache.go
diff options
context:
space:
mode:
Diffstat (limited to 'fetchers/cache.go')
-rw-r--r--fetchers/cache.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/fetchers/cache.go b/fetchers/cache.go
index 3802823..b45856d 100644
--- a/fetchers/cache.go
+++ b/fetchers/cache.go
@@ -161,6 +161,31 @@ func (c *Cache) GetPostsByDID(did string) ([]notes.Note, error) {
return posts, nil
}
+// returns how many posts we expect to have cached for an author
+// for detecting gaps caused by uneven TTL expiry
+func (c *Cache) GetPostCount(did string) (int, bool) {
+ key := fmt.Sprintf("post_count:%s", did)
+ count, err := c.client.Get(c.ctx, key).Int()
+ if err != nil {
+ return 0, false
+ }
+ return count, true
+}
+
+// resets the expected count. Used after a fresh fetch
+func (c *Cache) SetPostCount(did string, count int) {
+ key := fmt.Sprintf("post_count:%s", did)
+ c.client.Set(c.ctx, key, count, c.postExpiry)
+}
+
+// increments the expected post count. Used for continuation fetches
+// (fetching from a previous cursor) and jetstream events
+func (c *Cache) AddPostCount(did string, incr int) {
+ key := fmt.Sprintf("post_count:%s", did)
+ c.client.IncrBy(c.ctx, key, int64(incr))
+ c.client.Expire(c.ctx, key, c.postExpiry)
+}
+
// track oldest sent post per profile
func (c *Cache) GetOldestSent(did string) (time.Time, bool) {
key := fmt.Sprintf("oldest_sent:%s", did)