aboutsummaryrefslogtreecommitdiff
path: root/fetchers/cache.go
diff options
context:
space:
mode:
authorGuillermo Serrahima <dev@vylion.com>2026-07-16 02:38:46 +0200
committerGuillermo Serrahima <dev@vylion.com>2026-07-16 02:38:46 +0200
commit53ede6765a1583538b2abc3142d858464b3cf01c (patch)
tree422143cbc37098ebe0feb10b581c555e9f600005 /fetchers/cache.go
parent2f4f118bb755e92961c1225c49ff30ab4951daff (diff)
downloadllostre-53ede6765a1583538b2abc3142d858464b3cf01c.tar.xz
llostre-53ede6765a1583538b2abc3142d858464b3cf01c.zip
Implement fetched posts count tracking for catching gaps in cached postsHEADmain
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)