mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-15 01:37:29 -06:00
further work rewriting timeline caching
This commit is contained in:
parent
f4b4a696f2
commit
49d9a008d9
6 changed files with 230 additions and 327 deletions
80
internal/cache/timeline.go
vendored
80
internal/cache/timeline.go
vendored
|
|
@ -18,20 +18,17 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"codeberg.org/gruf/go-structr"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/cache/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
)
|
||||
|
||||
type TimelineCaches struct {
|
||||
|
||||
// Home ...
|
||||
Home TimelinesCache[*gtsmodel.Status]
|
||||
Home timeline.StatusTimelines
|
||||
|
||||
// List ...
|
||||
List TimelinesCache[*gtsmodel.Status]
|
||||
List timeline.StatusTimelines
|
||||
|
||||
// Public ...
|
||||
Public timeline.StatusTimeline
|
||||
|
|
@ -42,16 +39,7 @@ func (c *Caches) initHomeTimelines() {
|
|||
|
||||
log.Infof(nil, "cache size = %d", cap)
|
||||
|
||||
c.Timelines.Home.Init(structr.TimelineConfig[*gtsmodel.Status, string]{
|
||||
PKey: "StatusID",
|
||||
Indices: []structr.IndexConfig{
|
||||
{Fields: "StatusID"},
|
||||
{Fields: "AccountID"},
|
||||
{Fields: "BoostOfStatusID"},
|
||||
{Fields: "BoostOfAccountID"},
|
||||
},
|
||||
Copy: copyStatus,
|
||||
}, cap)
|
||||
c.Timelines.Home.Init(cap)
|
||||
}
|
||||
|
||||
func (c *Caches) initListTimelines() {
|
||||
|
|
@ -59,16 +47,7 @@ func (c *Caches) initListTimelines() {
|
|||
|
||||
log.Infof(nil, "cache size = %d", cap)
|
||||
|
||||
c.Timelines.List.Init(structr.TimelineConfig[*gtsmodel.Status, string]{
|
||||
PKey: "StatusID",
|
||||
Indices: []structr.IndexConfig{
|
||||
{Fields: "StatusID"},
|
||||
{Fields: "AccountID"},
|
||||
{Fields: "BoostOfStatusID"},
|
||||
{Fields: "BoostOfAccountID"},
|
||||
},
|
||||
Copy: copyStatus,
|
||||
}, cap)
|
||||
c.Timelines.List.Init(cap)
|
||||
}
|
||||
|
||||
func (c *Caches) initPublicTimeline() {
|
||||
|
|
@ -78,54 +57,3 @@ func (c *Caches) initPublicTimeline() {
|
|||
|
||||
c.Timelines.Public.Init(cap)
|
||||
}
|
||||
|
||||
type TimelineStatus struct {
|
||||
|
||||
// ID ...
|
||||
ID string
|
||||
|
||||
// AccountID ...
|
||||
AccountID string
|
||||
|
||||
// BoostOfID ...
|
||||
BoostOfID string
|
||||
|
||||
// BoostOfAccountID ...
|
||||
BoostOfAccountID string
|
||||
|
||||
// Local ...
|
||||
Local bool
|
||||
|
||||
// Loaded is a temporary field that may be
|
||||
// set for a newly loaded timeline status
|
||||
// so that statuses don't need to be loaded
|
||||
// from the database twice in succession.
|
||||
//
|
||||
// i.e. this will only be set if the status
|
||||
// was newly inserted into the timeline cache.
|
||||
// for existing cache items this will be nil.
|
||||
Loaded *gtsmodel.Status
|
||||
|
||||
// Prepared contains prepared frontend API
|
||||
// model for the referenced status. This may
|
||||
// or may-not be nil depending on whether the
|
||||
// status has been "unprepared" since the last
|
||||
// call to "prepare" the frontend model.
|
||||
Prepared *apimodel.Status
|
||||
}
|
||||
|
||||
func (s *TimelineStatus) Copy() *TimelineStatus {
|
||||
var prepared *apimodel.Status
|
||||
if s.Prepared != nil {
|
||||
prepared = new(apimodel.Status)
|
||||
*prepared = *s.Prepared
|
||||
}
|
||||
return &TimelineStatus{
|
||||
ID: s.ID,
|
||||
AccountID: s.AccountID,
|
||||
BoostOfID: s.BoostOfID,
|
||||
BoostOfAccountID: s.BoostOfAccountID,
|
||||
Loaded: nil, // NEVER set
|
||||
Prepared: prepared,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue