mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 16:02:25 -05:00
move boost checking to prepare function
This commit is contained in:
parent
6fa0033a45
commit
8c09d0f20d
2 changed files with 39 additions and 33 deletions
7
internal/cache/timeline/status.go
vendored
7
internal/cache/timeline/status.go
vendored
|
|
@ -279,12 +279,7 @@ func (t *StatusTimeline) Init(cap int) {
|
||||||
Indices: []structr.IndexConfig{
|
Indices: []structr.IndexConfig{
|
||||||
{Fields: "AccountID", Multiple: true},
|
{Fields: "AccountID", Multiple: true},
|
||||||
{Fields: "BoostOfAccountID", Multiple: true},
|
{Fields: "BoostOfAccountID", Multiple: true},
|
||||||
|
{Fields: "BoostOfID", Multiple: true},
|
||||||
// By setting multiple=false for BoostOfID, this will prevent
|
|
||||||
// timeline entries with matching BoostOfID will not be inserted
|
|
||||||
// after the first, which allows us to prevent repeated boosts
|
|
||||||
// of the same status from showing up within 'cap' entries.
|
|
||||||
{Fields: "BoostOfID", Multiple: false},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Timeline item copy function.
|
// Timeline item copy function.
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,40 @@ func (p *Processor) getStatusTimeline(
|
||||||
var apiStatuses []*apimodel.Status
|
var apiStatuses []*apimodel.Status
|
||||||
var lo, hi string
|
var lo, hi string
|
||||||
|
|
||||||
|
// Track whether a particular BoostOfID
|
||||||
|
// has already been boosted (i.e., seen)
|
||||||
|
// before in this paged request for statuses.
|
||||||
|
boosted := make(map[string]struct{}, 4)
|
||||||
|
alreadyBoosted := func(s *gtsmodel.Status) bool {
|
||||||
|
if s.BoostOfID != "" {
|
||||||
|
_, ok := boosted[s.BoostOfID]
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
boosted[s.BoostOfID] = struct{}{}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pre-prepared filter function that just ensures we
|
||||||
|
// don't end up serving multiple copies of the same boost.
|
||||||
|
prepare := func(status *gtsmodel.Status) (*apimodel.Status, error) {
|
||||||
|
if alreadyBoosted(status) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
apiStatus, err := p.converter.StatusToAPIStatus(ctx,
|
||||||
|
status,
|
||||||
|
requester,
|
||||||
|
filterCtx,
|
||||||
|
filters,
|
||||||
|
mutes,
|
||||||
|
)
|
||||||
|
if err != nil && !errors.Is(err, statusfilter.ErrHideStatus) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return apiStatus, nil
|
||||||
|
}
|
||||||
|
|
||||||
if cache != nil {
|
if cache != nil {
|
||||||
// Load status page via timeline cache, also
|
// Load status page via timeline cache, also
|
||||||
// getting lo, hi values for next, prev pages.
|
// getting lo, hi values for next, prev pages.
|
||||||
|
|
@ -134,20 +168,9 @@ func (p *Processor) getStatusTimeline(
|
||||||
// i.e. filter before caching.
|
// i.e. filter before caching.
|
||||||
filter,
|
filter,
|
||||||
|
|
||||||
// Frontend API model preparation function.
|
// Frontend API model
|
||||||
func(status *gtsmodel.Status) (*apimodel.Status, error) {
|
// preparation function.
|
||||||
apiStatus, err := p.converter.StatusToAPIStatus(ctx,
|
prepare,
|
||||||
status,
|
|
||||||
requester,
|
|
||||||
filterCtx,
|
|
||||||
filters,
|
|
||||||
mutes,
|
|
||||||
)
|
|
||||||
if err != nil && !errors.Is(err, statusfilter.ErrHideStatus) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return apiStatus, nil
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// Load status page without a receiving timeline cache.
|
// Load status page without a receiving timeline cache.
|
||||||
|
|
@ -159,19 +182,7 @@ func (p *Processor) getStatusTimeline(
|
||||||
return p.state.DB.GetStatusesByIDs(ctx, ids)
|
return p.state.DB.GetStatusesByIDs(ctx, ids)
|
||||||
},
|
},
|
||||||
filter,
|
filter,
|
||||||
func(status *gtsmodel.Status) (*apimodel.Status, error) {
|
prepare,
|
||||||
apiStatus, err := p.converter.StatusToAPIStatus(ctx,
|
|
||||||
status,
|
|
||||||
requester,
|
|
||||||
filterCtx,
|
|
||||||
filters,
|
|
||||||
mutes,
|
|
||||||
)
|
|
||||||
if err != nil && !errors.Is(err, statusfilter.ErrHideStatus) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return apiStatus, nil
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue