mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-04-26 11:04:43 +00:00
change the way we update lo,hi paging values during timeline load
This commit is contained in:
parent
c30c9b3bc5
commit
d8eba6d0f5
2 changed files with 30 additions and 30 deletions
26
internal/cache/timeline/status.go
vendored
26
internal/cache/timeline/status.go
vendored
|
@ -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...)
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue