mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 11:42:24 -06:00
start adding preloading support
This commit is contained in:
parent
6210ea33ee
commit
b3c9bfde18
7 changed files with 255 additions and 79 deletions
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||
)
|
||||
|
||||
|
|
@ -103,3 +104,36 @@ func (p *Processor) ListTimelineGet(
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
// preloadListTimeline will ensure that the timeline
|
||||
// cache for list owned by given account is preloaded.
|
||||
func (p *Processor) preloadListTimeline(
|
||||
ctx context.Context,
|
||||
account *gtsmodel.Account,
|
||||
list *gtsmodel.List,
|
||||
) error {
|
||||
|
||||
// Get (and so, create) list timeline cache for list ID.
|
||||
timeline := p.state.Caches.Timelines.List.MustGet(list.ID)
|
||||
|
||||
// Preload timeline with funcs.
|
||||
n, err := timeline.Preload(ctx,
|
||||
|
||||
// Database load function.
|
||||
func(page *paging.Page) ([]*gtsmodel.Status, error) {
|
||||
return p.state.DB.GetListTimeline(ctx, list.ID, page)
|
||||
},
|
||||
|
||||
// Status filtering function.
|
||||
func(status *gtsmodel.Status) (bool, error) {
|
||||
ok, err := p.visFilter.StatusHomeTimelineable(ctx, account, status)
|
||||
return !ok, err
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error preloading list timeline %s: %w", list.ID, err)
|
||||
}
|
||||
|
||||
log.Infof(ctx, "%s[%q]: preloaded %d", account.Username, list.Title, n)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue