mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-04-16 06:14:13 +00:00
ensure repeat boosts are marked in preloaded entries
This commit is contained in:
parent
ced560ebf8
commit
5c622d0fcd
1 changed files with 25 additions and 2 deletions
27
internal/cache/timeline/status.go
vendored
27
internal/cache/timeline/status.go
vendored
|
@ -34,6 +34,8 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
||||
)
|
||||
|
||||
const repeatBoostDepth = 40
|
||||
|
||||
// StatusMeta contains minimum viable metadata
|
||||
// about a Status in order to cache a timeline.
|
||||
type StatusMeta struct {
|
||||
|
@ -381,6 +383,29 @@ func (t *StatusTimeline) Preload(
|
|||
n = t.cache.Insert(metas...)
|
||||
}
|
||||
|
||||
// This is a potentially 100-1000s size map,
|
||||
// but still easily manageable memory-wise.
|
||||
recentBoosts := make(map[string]int, t.cut)
|
||||
|
||||
// Iterate the entire timeline cache and mark repeat boosts.
|
||||
for idx, value := range t.cache.RangeUnsafe(structr.Asc) {
|
||||
|
||||
// Store current ID in map.
|
||||
recentBoosts[value.ID] = idx
|
||||
|
||||
// If it's a boost, check if the original,
|
||||
// or a boost of it has been seen recently.
|
||||
if id := value.BoostOfID; id != "" {
|
||||
|
||||
// Check if seen recently.
|
||||
last := recentBoosts[id]
|
||||
value.repeatBoost = last < 40
|
||||
|
||||
// Update last-seen idx.
|
||||
recentBoosts[id] = idx
|
||||
}
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
|
@ -703,8 +728,6 @@ func LoadStatusTimeline(
|
|||
// the return value indicates whether the passed status has been boosted recently on the timeline.
|
||||
func (t *StatusTimeline) InsertOne(status *gtsmodel.Status, prepared *apimodel.Status) (repeatBoost bool) {
|
||||
if status.BoostOfID != "" {
|
||||
const repeatBoostDepth = 40
|
||||
|
||||
// Check through top $repeatBoostDepth number of timeline items.
|
||||
for i, value := range t.cache.RangeUnsafe(structr.Desc) {
|
||||
if i >= repeatBoostDepth {
|
||||
|
|
Loading…
Reference in a new issue