diff options
| author | Guillermo Serrahima <dev@vylion.com> | 2026-07-16 02:38:46 +0200 |
|---|---|---|
| committer | Guillermo Serrahima <dev@vylion.com> | 2026-07-16 02:38:46 +0200 |
| commit | 53ede6765a1583538b2abc3142d858464b3cf01c (patch) | |
| tree | 422143cbc37098ebe0feb10b581c555e9f600005 /main.go | |
| parent | 2f4f118bb755e92961c1225c49ff30ab4951daff (diff) | |
| download | llostre-main.tar.xz llostre-main.zip | |
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) } |
