[bugfix] Don't copy ptr fields in caches (#2386)

This commit is contained in:
tobi
2023-11-27 16:39:44 +01:00
committed by GitHub
parent 0bb9b72334
commit 33ee61575f
12 changed files with 469 additions and 109 deletions

329
internal/cache/gts.go vendored
View File

@ -306,6 +306,20 @@ func (c *GTSCaches) initAccount() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(a1 *gtsmodel.Account) *gtsmodel.Account {
a2 := new(gtsmodel.Account)
*a2 = *a1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/account.go.
a2.AvatarMediaAttachment = nil
a2.HeaderMediaAttachment = nil
a2.Emojis = nil
return a2
}
c.account = result.New([]result.Lookup{
{Name: "ID"},
{Name: "URI"},
@ -316,11 +330,7 @@ func (c *GTSCaches) initAccount() {
{Name: "OutboxURI"},
{Name: "FollowersURI"},
{Name: "FollowingURI"},
}, func(a1 *gtsmodel.Account) *gtsmodel.Account {
a2 := new(gtsmodel.Account)
*a2 = *a1
return a2
}, cap)
}, copyF, cap)
c.account.IgnoreErrors(ignoreErrors)
}
@ -334,14 +344,23 @@ func (c *GTSCaches) initAccountNote() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(n1 *gtsmodel.AccountNote) *gtsmodel.AccountNote {
n2 := new(gtsmodel.AccountNote)
*n2 = *n1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/relationship_note.go.
n2.Account = nil
n2.TargetAccount = nil
return n2
}
c.accountNote = result.New([]result.Lookup{
{Name: "ID"},
{Name: "AccountID.TargetAccountID"},
}, func(n1 *gtsmodel.AccountNote) *gtsmodel.AccountNote {
n2 := new(gtsmodel.AccountNote)
*n2 = *n1
return n2
}, cap)
}, copyF, cap)
c.accountNote.IgnoreErrors(ignoreErrors)
}
@ -376,17 +395,26 @@ func (c *GTSCaches) initBlock() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(b1 *gtsmodel.Block) *gtsmodel.Block {
b2 := new(gtsmodel.Block)
*b2 = *b1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/relationship_block.go.
b2.Account = nil
b2.TargetAccount = nil
return b2
}
c.block = result.New([]result.Lookup{
{Name: "ID"},
{Name: "URI"},
{Name: "AccountID.TargetAccountID"},
{Name: "AccountID", Multi: true},
{Name: "TargetAccountID", Multi: true},
}, func(b1 *gtsmodel.Block) *gtsmodel.Block {
b2 := new(gtsmodel.Block)
*b2 = *b1
return b2
}, cap)
}, copyF, cap)
c.block.IgnoreErrors(ignoreErrors)
}
@ -436,17 +464,25 @@ func (c *GTSCaches) initEmoji() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(e1 *gtsmodel.Emoji) *gtsmodel.Emoji {
e2 := new(gtsmodel.Emoji)
*e2 = *e1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/emoji.go.
e2.Category = nil
return e2
}
c.emoji = result.New([]result.Lookup{
{Name: "ID"},
{Name: "URI"},
{Name: "Shortcode.Domain", AllowZero: true /* domain can be zero i.e. "" */},
{Name: "ImageStaticURL"},
{Name: "CategoryID", Multi: true},
}, func(e1 *gtsmodel.Emoji) *gtsmodel.Emoji {
e2 := new(gtsmodel.Emoji)
*e2 = *e1
return e2
}, cap)
}, copyF, cap)
c.emoji.IgnoreErrors(ignoreErrors)
}
@ -481,17 +517,26 @@ func (c *GTSCaches) initFollow() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(f1 *gtsmodel.Follow) *gtsmodel.Follow {
f2 := new(gtsmodel.Follow)
*f2 = *f1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/relationship_follow.go.
f2.Account = nil
f2.TargetAccount = nil
return f2
}
c.follow = result.New([]result.Lookup{
{Name: "ID"},
{Name: "URI"},
{Name: "AccountID.TargetAccountID"},
{Name: "AccountID", Multi: true},
{Name: "TargetAccountID", Multi: true},
}, func(f1 *gtsmodel.Follow) *gtsmodel.Follow {
f2 := new(gtsmodel.Follow)
*f2 = *f1
return f2
}, cap)
}, copyF, cap)
c.follow.IgnoreErrors(ignoreErrors)
}
@ -519,17 +564,26 @@ func (c *GTSCaches) initFollowRequest() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(f1 *gtsmodel.FollowRequest) *gtsmodel.FollowRequest {
f2 := new(gtsmodel.FollowRequest)
*f2 = *f1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/relationship_follow_req.go.
f2.Account = nil
f2.TargetAccount = nil
return f2
}
c.followRequest = result.New([]result.Lookup{
{Name: "ID"},
{Name: "URI"},
{Name: "AccountID.TargetAccountID"},
{Name: "AccountID", Multi: true},
{Name: "TargetAccountID", Multi: true},
}, func(f1 *gtsmodel.FollowRequest) *gtsmodel.FollowRequest {
f2 := new(gtsmodel.FollowRequest)
*f2 = *f1
return f2
}, cap)
}, copyF, cap)
c.followRequest.IgnoreErrors(ignoreErrors)
}
@ -571,14 +625,23 @@ func (c *GTSCaches) initInstance() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(i1 *gtsmodel.Instance) *gtsmodel.Instance {
i2 := new(gtsmodel.Instance)
*i2 = *i1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/instance.go.
i2.DomainBlock = nil
i2.ContactAccount = nil
return i1
}
c.instance = result.New([]result.Lookup{
{Name: "ID"},
{Name: "Domain"},
}, func(i1 *gtsmodel.Instance) *gtsmodel.Instance {
i2 := new(gtsmodel.Instance)
*i2 = *i1
return i1
}, cap)
}, copyF, cap)
c.instance.IgnoreErrors(ignoreErrors)
}
@ -592,13 +655,22 @@ func (c *GTSCaches) initList() {
log.Infof(nil, "cache size = %d", cap)
c.list = result.New([]result.Lookup{
{Name: "ID"},
}, func(l1 *gtsmodel.List) *gtsmodel.List {
copyF := func(l1 *gtsmodel.List) *gtsmodel.List {
l2 := new(gtsmodel.List)
*l2 = *l1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/list.go.
l2.Account = nil
l2.ListEntries = nil
return l2
}, cap)
}
c.list = result.New([]result.Lookup{
{Name: "ID"},
}, copyF, cap)
c.list.IgnoreErrors(ignoreErrors)
}
@ -612,15 +684,23 @@ func (c *GTSCaches) initListEntry() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(l1 *gtsmodel.ListEntry) *gtsmodel.ListEntry {
l2 := new(gtsmodel.ListEntry)
*l2 = *l1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/list.go.
l2.Follow = nil
return l2
}
c.listEntry = result.New([]result.Lookup{
{Name: "ID"},
{Name: "ListID", Multi: true},
{Name: "FollowID", Multi: true},
}, func(l1 *gtsmodel.ListEntry) *gtsmodel.ListEntry {
l2 := new(gtsmodel.ListEntry)
*l2 = *l1
return l2
}, cap)
}, copyF, cap)
c.listEntry.IgnoreErrors(ignoreErrors)
}
@ -674,13 +754,23 @@ func (c *GTSCaches) initMention() {
log.Infof(nil, "cache size = %d", cap)
c.mention = result.New([]result.Lookup{
{Name: "ID"},
}, func(m1 *gtsmodel.Mention) *gtsmodel.Mention {
copyF := func(m1 *gtsmodel.Mention) *gtsmodel.Mention {
m2 := new(gtsmodel.Mention)
*m2 = *m1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/mention.go.
m2.Status = nil
m2.OriginAccount = nil
m2.TargetAccount = nil
return m2
}, cap)
}
c.mention = result.New([]result.Lookup{
{Name: "ID"},
}, copyF, cap)
c.mention.IgnoreErrors(ignoreErrors)
}
@ -694,14 +784,24 @@ func (c *GTSCaches) initNotification() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(n1 *gtsmodel.Notification) *gtsmodel.Notification {
n2 := new(gtsmodel.Notification)
*n2 = *n1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/notification.go.
n2.Status = nil
n2.OriginAccount = nil
n2.TargetAccount = nil
return n2
}
c.notification = result.New([]result.Lookup{
{Name: "ID"},
{Name: "NotificationType.TargetAccountID.OriginAccountID.StatusID"},
}, func(n1 *gtsmodel.Notification) *gtsmodel.Notification {
n2 := new(gtsmodel.Notification)
*n2 = *n1
return n2
}, cap)
}, copyF, cap)
c.notification.IgnoreErrors(ignoreErrors)
}
@ -715,14 +815,22 @@ func (c *GTSCaches) initPoll() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(p1 *gtsmodel.Poll) *gtsmodel.Poll {
p2 := new(gtsmodel.Poll)
*p2 = *p1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/poll.go.
p2.Status = nil
return p2
}
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)
}, copyF, cap)
c.poll.IgnoreErrors(ignoreErrors)
}
@ -736,15 +844,24 @@ func (c *GTSCaches) initPollVote() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(v1 *gtsmodel.PollVote) *gtsmodel.PollVote {
v2 := new(gtsmodel.PollVote)
*v2 = *v1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/poll.go.
v2.Account = nil
v2.Poll = nil
return v2
}
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)
}, copyF, cap)
c.pollVote.IgnoreErrors(ignoreErrors)
}
@ -772,13 +889,25 @@ func (c *GTSCaches) initReport() {
log.Infof(nil, "cache size = %d", cap)
c.report = result.New([]result.Lookup{
{Name: "ID"},
}, func(r1 *gtsmodel.Report) *gtsmodel.Report {
copyF := func(r1 *gtsmodel.Report) *gtsmodel.Report {
r2 := new(gtsmodel.Report)
*r2 = *r1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/report.go.
r2.Account = nil
r2.TargetAccount = nil
r2.Statuses = nil
r2.Rules = nil
r2.ActionTakenByAccount = nil
return r2
}, cap)
}
c.report = result.New([]result.Lookup{
{Name: "ID"},
}, copyF, cap)
c.report.IgnoreErrors(ignoreErrors)
}
@ -792,17 +921,35 @@ func (c *GTSCaches) initStatus() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(s1 *gtsmodel.Status) *gtsmodel.Status {
s2 := new(gtsmodel.Status)
*s2 = *s1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/status.go.
s2.Account = nil
s2.InReplyTo = nil
s2.InReplyToAccount = nil
s2.BoostOf = nil
s2.BoostOfAccount = nil
s2.Poll = nil
s2.Attachments = nil
s2.Tags = nil
s2.Mentions = nil
s2.Emojis = nil
s2.CreatedWithApplication = nil
return s2
}
c.status = result.New([]result.Lookup{
{Name: "ID"},
{Name: "URI"},
{Name: "URL"},
{Name: "BoostOfID.AccountID"},
{Name: "ThreadID", Multi: true},
}, func(s1 *gtsmodel.Status) *gtsmodel.Status {
s2 := new(gtsmodel.Status)
*s2 = *s1
return s2
}, cap)
}, copyF, cap)
c.status.IgnoreErrors(ignoreErrors)
}
@ -816,15 +963,25 @@ func (c *GTSCaches) initStatusFave() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(f1 *gtsmodel.StatusFave) *gtsmodel.StatusFave {
f2 := new(gtsmodel.StatusFave)
*f2 = *f1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/statusfave.go.
f2.Account = nil
f2.TargetAccount = nil
f2.Status = nil
return f2
}
c.statusFave = result.New([]result.Lookup{
{Name: "ID"},
{Name: "AccountID.StatusID"},
{Name: "StatusID", Multi: true},
}, func(f1 *gtsmodel.StatusFave) *gtsmodel.StatusFave {
f2 := new(gtsmodel.StatusFave)
*f2 = *f1
return f2
}, cap)
}, copyF, cap)
c.statusFave.IgnoreErrors(ignoreErrors)
}
@ -916,17 +1073,25 @@ func (c *GTSCaches) initUser() {
log.Infof(nil, "cache size = %d", cap)
copyF := func(u1 *gtsmodel.User) *gtsmodel.User {
u2 := new(gtsmodel.User)
*u2 = *u1
// Don't include ptr fields that
// will be populated separately.
// See internal/db/bundb/user.go.
u2.Account = nil
return u2
}
c.user = result.New([]result.Lookup{
{Name: "ID"},
{Name: "AccountID"},
{Name: "Email"},
{Name: "ConfirmationToken"},
{Name: "ExternalID"},
}, func(u1 *gtsmodel.User) *gtsmodel.User {
u2 := new(gtsmodel.User)
*u2 = *u1
return u2
}, cap)
}, copyF, cap)
c.user.IgnoreErrors(ignoreErrors)
}