diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -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) } |
