mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-03 12:52:26 -06:00
change the way we update lo,hi paging values during timeline load
This commit is contained in:
parent
791d7c5aef
commit
158463908a
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
|
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.
|
// the slices.DeleteFunc() signature requirements.
|
||||||
func (m *StatusMeta) isLoaded() bool {
|
func (m *StatusMeta) isNotLoaded() bool {
|
||||||
return m.loaded == nil
|
return m.loaded == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -413,7 +413,7 @@ func (t *StatusTimeline) Load(
|
||||||
hi = metas[0].ID
|
hi = metas[0].ID
|
||||||
|
|
||||||
// Drop all entries we failed to load statuses for.
|
// 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.
|
// Perform post-filtering on cached status entries.
|
||||||
metas, err = doStatusPostFilter(metas, postFilter)
|
metas, err = doStatusPostFilter(metas, postFilter)
|
||||||
|
|
@ -467,6 +467,9 @@ func (t *StatusTimeline) Load(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update returned lo paging value.
|
||||||
|
lo = statuses[len(statuses)-1].ID
|
||||||
|
|
||||||
// Convert to our cache type,
|
// Convert to our cache type,
|
||||||
// these will get inserted into
|
// these will get inserted into
|
||||||
// the cache in prepare() below.
|
// the cache in prepare() below.
|
||||||
|
|
@ -515,20 +518,15 @@ func (t *StatusTimeline) Load(
|
||||||
|
|
||||||
// Using meta and funcs, prepare frontend API models.
|
// Using meta and funcs, prepare frontend API models.
|
||||||
apiStatuses = prepareStatuses(ctx, metas, prepareAPI)
|
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 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
|
// Even if we don't return them, insert
|
||||||
// the excess (post-filtered) into cache.
|
// the excess (post-filtered) into cache.
|
||||||
t.cache.Insert(justLoaded...)
|
t.cache.Insert(justLoaded...)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,22 @@ func (p *Processor) HomeTimelineGet(
|
||||||
*apimodel.PageableResponse,
|
*apimodel.PageableResponse,
|
||||||
gtserror.WithCode,
|
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,
|
return p.getStatusTimeline(ctx,
|
||||||
|
|
||||||
// Auth'd
|
// Auth'd
|
||||||
|
|
@ -58,12 +74,7 @@ func (p *Processor) HomeTimelineGet(
|
||||||
// page query flag, (this map
|
// page query flag, (this map
|
||||||
// later gets copied before
|
// later gets copied before
|
||||||
// any further usage).
|
// any further usage).
|
||||||
func() url.Values {
|
pageQuery,
|
||||||
if local {
|
|
||||||
return localOnlyTrue
|
|
||||||
}
|
|
||||||
return localOnlyFalse
|
|
||||||
}(),
|
|
||||||
|
|
||||||
// Status filter context.
|
// Status filter context.
|
||||||
statusfilter.FilterContextHome,
|
statusfilter.FilterContextHome,
|
||||||
|
|
@ -84,15 +95,6 @@ func (p *Processor) HomeTimelineGet(
|
||||||
|
|
||||||
// Post-filtering function,
|
// Post-filtering function,
|
||||||
// i.e. filter after caching.
|
// i.e. filter after caching.
|
||||||
func(s *gtsmodel.Status) (bool, error) {
|
postFilter,
|
||||||
|
|
||||||
// Remove any non-local statuses
|
|
||||||
// if requester wants local-only.
|
|
||||||
if local && !*s.Local {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, nil
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue