diff --git a/internal/cache/timeline/status.go b/internal/cache/timeline/status.go index 7366cae91..b527125e6 100644 --- a/internal/cache/timeline/status.go +++ b/internal/cache/timeline/status.go @@ -61,9 +61,9 @@ type StatusMeta struct { loaded *gtsmodel.Status } -// isLoaded is a small utility func that can fill +// isNotLoaded is a small utility func that can fill // the slices.DeleteFunc() signature requirements. -func (m *StatusMeta) isLoaded() bool { +func (m *StatusMeta) isNotLoaded() bool { return m.loaded == nil } @@ -413,7 +413,7 @@ func (t *StatusTimeline) Load( hi = metas[0].ID // Drop all entries we failed to load statuses for. - metas = slices.DeleteFunc(metas, (*StatusMeta).isLoaded) + metas = slices.DeleteFunc(metas, (*StatusMeta).isNotLoaded) // Perform post-filtering on cached status entries. metas, err = doStatusPostFilter(metas, postFilter) @@ -467,6 +467,9 @@ func (t *StatusTimeline) Load( continue } + // Update returned lo paging value. + lo = statuses[len(statuses)-1].ID + // Convert to our cache type, // these will get inserted into // the cache in prepare() below. @@ -515,20 +518,15 @@ func (t *StatusTimeline) Load( // Using meta and funcs, prepare frontend API models. apiStatuses = prepareStatuses(ctx, metas, prepareAPI) - - if hi == "" { - // No cached statuses were previously - // loaded, we need to determine a hi - // paging value from recently loaded. - hi = metas[0].ID - } - - // In case extra statuses were loaded, - // set lo paging value to last value. - lo = metas[len(metas)-1].ID } if len(justLoaded) > 0 { + if hi == "" { + // No previously cached, set + // hi paging value from loaded. + hi = justLoaded[0].ID + } + // Even if we don't return them, insert // the excess (post-filtered) into cache. t.cache.Insert(justLoaded...) diff --git a/internal/processing/timeline/home.go b/internal/processing/timeline/home.go index 468d038a4..0aa8f2ff1 100644 --- a/internal/processing/timeline/home.go +++ b/internal/processing/timeline/home.go @@ -38,6 +38,22 @@ func (p *Processor) HomeTimelineGet( *apimodel.PageableResponse, gtserror.WithCode, ) { + var pageQuery url.Values + var postFilter func(*gtsmodel.Status) (bool, error) + + if local { + // Set local = true query. + pageQuery = localOnlyTrue + + // Remove any non-local statuses if local-only requested. + postFilter = func(s *gtsmodel.Status) (bool, error) { + return !*s.Local, nil + } + } else { + // Set local = false query. + pageQuery = localOnlyFalse + } + return p.getStatusTimeline(ctx, // Auth'd @@ -58,12 +74,7 @@ func (p *Processor) HomeTimelineGet( // page query flag, (this map // later gets copied before // any further usage). - func() url.Values { - if local { - return localOnlyTrue - } - return localOnlyFalse - }(), + pageQuery, // Status filter context. statusfilter.FilterContextHome, @@ -84,15 +95,6 @@ func (p *Processor) HomeTimelineGet( // Post-filtering function, // i.e. filter after caching. - func(s *gtsmodel.Status) (bool, error) { - - // Remove any non-local statuses - // if requester wants local-only. - if local && !*s.Local { - return true, nil - } - - return false, nil - }, + postFilter, ) }