aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/main.go b/main.go
index 85c8712..6fb7bcf 100644
--- a/main.go
+++ b/main.go
@@ -373,14 +373,28 @@ func postsHandler(w http.ResponseWriter, r *http.Request) {
}
config.Logger.Debug("posts ready", "count", len(posts))
- // background refetch if cache is running low
+ // background refetch if cache is running low or has developed a gap
oldestSent, hasOldest := config.Cache.GetOldestSent(session.DID)
if !hasOldest || len(posts) > 0 {
oldest := posts[len(posts)-1].CreatedAt
count, _ := config.Cache.CountPostsOlderThan(session.DID, oldest)
cursor, hasCursor := config.Cache.GetCursor(session.DID)
- config.Logger.Debug("refetch check", "count", count, "pageSize", config.PageSize, "hasCursor", hasCursor, "oldest", oldest)
- if count < config.PageSize && hasCursor {
+
+ // skip right after a fresh fetch; expected count was just reset to match it
+ hasGap := false
+ if len(cached) > 0 {
+ if expectedCount, hasExpected := config.Cache.GetPostCount(session.DID); hasExpected {
+ hasGap = len(cached) < expectedCount
+ }
+ }
+
+ config.Logger.Debug("refetch check", "count", count, "pageSize", config.PageSize, "hasCursor", hasCursor, "oldest", oldest, "hasGap", hasGap)
+
+ switch {
+ case hasGap:
+ sessionCopy := session.Copy()
+ go fetchers.FetchAppBskyFeedPostsWithCursor(config, sessionCopy.DID, sessionCopy.PDS, sessionCopy, "")
+ case count < config.PageSize && hasCursor:
sessionCopy := session.Copy()
go fetchers.FetchAppBskyFeedPostsWithCursor(config, sessionCopy.DID, sessionCopy.PDS, sessionCopy, cursor)
}