mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-17 15:57:35 -06:00
implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
This commit is contained in:
parent
bc46cd72b6
commit
4803ae6bad
5 changed files with 82 additions and 86 deletions
1
internal/cache/cache.go
vendored
1
internal/cache/cache.go
vendored
|
|
@ -216,7 +216,6 @@ func (c *Caches) Sweep(threshold float64) {
|
|||
c.Timelines.Home.Trim(threshold)
|
||||
c.Timelines.List.Trim(threshold)
|
||||
c.Timelines.Public.Trim(threshold)
|
||||
c.Timelines.Local.Trim(threshold)
|
||||
c.Visibility.Trim(threshold)
|
||||
}
|
||||
|
||||
|
|
|
|||
11
internal/cache/timeline.go
vendored
11
internal/cache/timeline.go
vendored
|
|
@ -32,9 +32,6 @@ type TimelineCaches struct {
|
|||
|
||||
// Public ...
|
||||
Public timeline.StatusTimeline
|
||||
|
||||
// Local ...
|
||||
Local timeline.StatusTimeline
|
||||
}
|
||||
|
||||
func (c *Caches) initHomeTimelines() {
|
||||
|
|
@ -60,11 +57,3 @@ func (c *Caches) initPublicTimeline() {
|
|||
|
||||
c.Timelines.Public.Init(cap)
|
||||
}
|
||||
|
||||
func (c *Caches) initLocalTimeline() {
|
||||
cap := 1000
|
||||
|
||||
log.Infof(nil, "cache size = %d", cap)
|
||||
|
||||
c.Timelines.Local.Init(cap)
|
||||
}
|
||||
|
|
|
|||
54
internal/cache/timeline/status.go
vendored
54
internal/cache/timeline/status.go
vendored
|
|
@ -159,7 +159,12 @@ func (t *StatusTimelines) Delete(key string) {
|
|||
}
|
||||
}
|
||||
|
||||
// Insert ...
|
||||
// InsertInto allows you to bulk insert many statuses into timeline mapped by key.
|
||||
func (t *StatusTimelines) InsertInto(key string, statuses ...*gtsmodel.Status) {
|
||||
t.MustGet(key).Insert(statuses...)
|
||||
}
|
||||
|
||||
// Insert allows you to bulk insert many statuses into *all* mapped timelines.
|
||||
func (t *StatusTimelines) Insert(statuses ...*gtsmodel.Status) {
|
||||
meta := toStatusMeta(statuses)
|
||||
if p := t.ptr.Load(); p != nil {
|
||||
|
|
@ -169,11 +174,6 @@ func (t *StatusTimelines) Insert(statuses ...*gtsmodel.Status) {
|
|||
}
|
||||
}
|
||||
|
||||
// InsertInto ...
|
||||
func (t *StatusTimelines) InsertInto(key string, statuses ...*gtsmodel.Status) {
|
||||
t.MustGet(key).Insert(statuses...)
|
||||
}
|
||||
|
||||
// RemoveByStatusIDs ...
|
||||
func (t *StatusTimelines) RemoveByStatusIDs(statusIDs ...string) {
|
||||
if p := t.ptr.Load(); p != nil {
|
||||
|
|
@ -210,6 +210,15 @@ func (t *StatusTimelines) UnprepareByAccountIDs(accountIDs ...string) {
|
|||
}
|
||||
}
|
||||
|
||||
// UnprepareAll ...
|
||||
func (t *StatusTimelines) UnprepareAll() {
|
||||
if p := t.ptr.Load(); p != nil {
|
||||
for _, tt := range *p {
|
||||
tt.UnprepareAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Trim ...
|
||||
func (t *StatusTimelines) Trim(threshold float64) {
|
||||
if p := t.ptr.Load(); p != nil {
|
||||
|
|
@ -470,7 +479,20 @@ func (t *StatusTimeline) Load(
|
|||
return apiStatuses, lo, hi, nil
|
||||
}
|
||||
|
||||
// Insert ...
|
||||
// InsertOne allows you to insert a single status into the timeline, with optional prepared API model.
|
||||
func (t *StatusTimeline) InsertOne(status *gtsmodel.Status, prepared *apimodel.Status) {
|
||||
t.cache.Insert(&StatusMeta{
|
||||
ID: status.ID,
|
||||
AccountID: status.AccountID,
|
||||
BoostOfID: status.BoostOfID,
|
||||
BoostOfAccountID: status.BoostOfAccountID,
|
||||
Local: *status.Local,
|
||||
loaded: status,
|
||||
prepared: prepared,
|
||||
})
|
||||
}
|
||||
|
||||
// Insert allows you to bulk insert many statuses into the timeline.
|
||||
func (t *StatusTimeline) Insert(statuses ...*gtsmodel.Status) {
|
||||
t.cache.Insert(toStatusMeta(statuses)...)
|
||||
}
|
||||
|
|
@ -595,6 +617,14 @@ func (t *StatusTimeline) UnprepareByAccountIDs(accountIDs ...string) {
|
|||
}
|
||||
}
|
||||
|
||||
// UnprepareAll removes cached frontend API
|
||||
// models for all cached timeline entries.
|
||||
func (t *StatusTimeline) UnprepareAll() {
|
||||
for value := range t.cache.RangeUnsafe(structr.Asc) {
|
||||
value.prepared = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Trim ...
|
||||
func (t *StatusTimeline) Trim(threshold float64) {
|
||||
|
||||
|
|
@ -690,7 +720,8 @@ func loadStatuses(
|
|||
metas []*StatusMeta,
|
||||
loadIDs func([]string) ([]*gtsmodel.Status, error),
|
||||
) error {
|
||||
// ...
|
||||
// Determine which of our passed status
|
||||
// meta objects still need statuses loading.
|
||||
toLoadIDs := make([]string, len(metas))
|
||||
loadedMap := make(map[string]*StatusMeta, len(metas))
|
||||
for i, meta := range metas {
|
||||
|
|
@ -733,7 +764,8 @@ func toStatusMeta(statuses []*gtsmodel.Status) []*StatusMeta {
|
|||
})
|
||||
}
|
||||
|
||||
// ...
|
||||
// doStatusPreFilter performs given filter function on provided statuses,
|
||||
// returning early if an error is returned. returns filtered statuses.
|
||||
func doStatusPreFilter(statuses []*gtsmodel.Status, filter func(*gtsmodel.Status) (bool, error)) ([]*gtsmodel.Status, error) {
|
||||
|
||||
// Check for provided
|
||||
|
|
@ -765,7 +797,9 @@ func doStatusPreFilter(statuses []*gtsmodel.Status, filter func(*gtsmodel.Status
|
|||
return statuses, nil
|
||||
}
|
||||
|
||||
// ...
|
||||
// doStatusPostFilter performs given filter function on provided status meta,
|
||||
// expecting that embedded status is already loaded, returning filtered status
|
||||
// meta, as well as those *filtered out*. returns early if error is returned.
|
||||
func doStatusPostFilter(metas []*StatusMeta, filter func(*gtsmodel.Status) (bool, error)) ([]*StatusMeta, []*StatusMeta, error) {
|
||||
|
||||
// Check for provided
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue