[feature] add support for polls + receiving federated status edits (#2330)

This commit is contained in:
kim
2023-11-08 14:32:17 +00:00
committed by GitHub
parent 7204ccedc3
commit e9e5dc5a40
84 changed files with 3992 additions and 570 deletions

98
internal/cache/gts.go vendored
View File

@@ -52,6 +52,9 @@ type GTSCaches struct {
media *result.Cache[*gtsmodel.MediaAttachment]
mention *result.Cache[*gtsmodel.Mention]
notification *result.Cache[*gtsmodel.Notification]
poll *result.Cache[*gtsmodel.Poll]
pollVote *result.Cache[*gtsmodel.PollVote]
pollVoteIDs *SliceCache[string]
report *result.Cache[*gtsmodel.Report]
status *result.Cache[*gtsmodel.Status]
statusFave *result.Cache[*gtsmodel.StatusFave]
@@ -90,6 +93,9 @@ func (c *GTSCaches) Init() {
c.initMedia()
c.initMention()
c.initNotification()
c.initPoll()
c.initPollVote()
c.initPollVoteIDs()
c.initReport()
c.initStatus()
c.initStatusFave()
@@ -231,6 +237,21 @@ func (c *GTSCaches) Notification() *result.Cache[*gtsmodel.Notification] {
return c.notification
}
// Poll provides access to the gtsmodel Poll database cache.
func (c *GTSCaches) Poll() *result.Cache[*gtsmodel.Poll] {
return c.poll
}
// PollVote provides access to the gtsmodel PollVote database cache.
func (c *GTSCaches) PollVote() *result.Cache[*gtsmodel.PollVote] {
return c.pollVote
}
// PollVoteIDs provides access to the poll vote IDs list database cache.
func (c *GTSCaches) PollVoteIDs() *SliceCache[string] {
return c.pollVoteIDs
}
// Report provides access to the gtsmodel Report database cache.
func (c *GTSCaches) Report() *result.Cache[*gtsmodel.Report] {
return c.report
@@ -246,26 +267,26 @@ func (c *GTSCaches) StatusFave() *result.Cache[*gtsmodel.StatusFave] {
return c.statusFave
}
// Tag provides access to the gtsmodel Tag database cache.
func (c *GTSCaches) Tag() *result.Cache[*gtsmodel.Tag] {
return c.tag
}
// ThreadMute provides access to the gtsmodel ThreadMute database cache.
func (c *GTSCaches) ThreadMute() *result.Cache[*gtsmodel.ThreadMute] {
return c.threadMute
}
// StatusFaveIDs provides access to the status fave IDs list database cache.
func (c *GTSCaches) StatusFaveIDs() *SliceCache[string] {
return c.statusFaveIDs
}
// Tag provides access to the gtsmodel Tag database cache.
func (c *GTSCaches) Tag() *result.Cache[*gtsmodel.Tag] {
return c.tag
}
// Tombstone provides access to the gtsmodel Tombstone database cache.
func (c *GTSCaches) Tombstone() *result.Cache[*gtsmodel.Tombstone] {
return c.tombstone
}
// ThreadMute provides access to the gtsmodel ThreadMute database cache.
func (c *GTSCaches) ThreadMute() *result.Cache[*gtsmodel.ThreadMute] {
return c.threadMute
}
// User provides access to the gtsmodel User database cache.
func (c *GTSCaches) User() *result.Cache[*gtsmodel.User] {
return c.user
@@ -685,6 +706,63 @@ func (c *GTSCaches) initNotification() {
c.notification.IgnoreErrors(ignoreErrors)
}
func (c *GTSCaches) initPoll() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(
sizeofPoll(), // model in-mem size.
config.GetCachePollMemRatio(),
)
log.Infof(nil, "cache size = %d", cap)
c.poll = result.New([]result.Lookup{
{Name: "ID"},
{Name: "StatusID"},
}, func(p1 *gtsmodel.Poll) *gtsmodel.Poll {
p2 := new(gtsmodel.Poll)
*p2 = *p1
return p2
}, cap)
c.poll.IgnoreErrors(ignoreErrors)
}
func (c *GTSCaches) initPollVote() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(
sizeofPollVote(), // model in-mem size.
config.GetCachePollVoteMemRatio(),
)
log.Infof(nil, "cache size = %d", cap)
c.pollVote = result.New([]result.Lookup{
{Name: "ID"},
{Name: "PollID.AccountID"},
{Name: "PollID", Multi: true},
}, func(v1 *gtsmodel.PollVote) *gtsmodel.PollVote {
v2 := new(gtsmodel.PollVote)
*v2 = *v1
return v2
}, cap)
c.pollVote.IgnoreErrors(ignoreErrors)
}
func (c *GTSCaches) initPollVoteIDs() {
// Calculate maximum cache size.
cap := calculateSliceCacheMax(
config.GetCachePollVoteIDsMemRatio(),
)
log.Infof(nil, "cache size = %d", cap)
c.pollVoteIDs = &SliceCache[string]{Cache: simple.New[string, []string](
0,
cap,
)}
}
func (c *GTSCaches) initReport() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(