mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-13 04:57:29 -06:00
remove old timeline package, add local timeline cache
This commit is contained in:
parent
4803ae6bad
commit
566e2b1d38
21 changed files with 105 additions and 2943 deletions
|
|
@ -19,7 +19,6 @@ package timeline
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
|
||||
|
|
@ -37,6 +36,20 @@ func (p *Processor) PublicTimelineGet(
|
|||
) (
|
||||
*apimodel.PageableResponse,
|
||||
gtserror.WithCode,
|
||||
) {
|
||||
if local {
|
||||
return p.localTimelineGet(ctx, requester, page)
|
||||
}
|
||||
return p.publicTimelineGet(ctx, requester, page)
|
||||
}
|
||||
|
||||
func (p *Processor) publicTimelineGet(
|
||||
ctx context.Context,
|
||||
requester *gtsmodel.Account,
|
||||
page *paging.Page,
|
||||
) (
|
||||
*apimodel.PageableResponse,
|
||||
gtserror.WithCode,
|
||||
) {
|
||||
return p.getStatusTimeline(ctx,
|
||||
|
||||
|
|
@ -58,12 +71,7 @@ func (p *Processor) PublicTimelineGet(
|
|||
// page query flag, (this map
|
||||
// later gets copied before
|
||||
// any further usage).
|
||||
func() url.Values {
|
||||
if local {
|
||||
return localOnlyTrue
|
||||
}
|
||||
return localOnlyFalse
|
||||
}(),
|
||||
localOnlyFalse,
|
||||
|
||||
// Status filter context.
|
||||
statusfilter.FilterContextPublic,
|
||||
|
|
@ -81,11 +89,58 @@ func (p *Processor) PublicTimelineGet(
|
|||
// 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
|
||||
}
|
||||
// Check the visibility of passed status to requesting user.
|
||||
ok, err := p.visFilter.StatusPublicTimelineable(ctx, requester, s)
|
||||
return !ok, err
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (p *Processor) localTimelineGet(
|
||||
ctx context.Context,
|
||||
requester *gtsmodel.Account,
|
||||
page *paging.Page,
|
||||
) (
|
||||
*apimodel.PageableResponse,
|
||||
gtserror.WithCode,
|
||||
) {
|
||||
return p.getStatusTimeline(ctx,
|
||||
|
||||
// Auth'd
|
||||
// account.
|
||||
requester,
|
||||
|
||||
// Global local timeline cache.
|
||||
&p.state.Caches.Timelines.Local,
|
||||
|
||||
// Current
|
||||
// page.
|
||||
page,
|
||||
|
||||
// Public timeline endpoint.
|
||||
"/api/v1/timelines/public",
|
||||
|
||||
// Set local-only timeline
|
||||
// page query flag, (this map
|
||||
// later gets copied before
|
||||
// any further usage).
|
||||
localOnlyTrue,
|
||||
|
||||
// Status filter context.
|
||||
statusfilter.FilterContextPublic,
|
||||
|
||||
// Database load function.
|
||||
func(pg *paging.Page) (statuses []*gtsmodel.Status, err error) {
|
||||
return p.state.DB.GetLocalTimeline(ctx, pg)
|
||||
},
|
||||
|
||||
// Pre-filtering function,
|
||||
// i.e. filter before caching.
|
||||
nil,
|
||||
|
||||
// Post-filtering function,
|
||||
// i.e. filter after caching.
|
||||
func(s *gtsmodel.Status) (bool, error) {
|
||||
|
||||
// Check the visibility of passed status to requesting user.
|
||||
ok, err := p.visFilter.StatusPublicTimelineable(ctx, requester, s)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue