Skip to content

Commit

Permalink
[bugfix] more robust list timeline invalidation (#1995)
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaaaWhatsUpDoc authored Jul 18, 2023
1 parent 346ecab commit f431974
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 214 deletions.
9 changes: 8 additions & 1 deletion internal/api/util/parsequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ func requiredError(key string) gtserror.WithCode {
*/

func ParseLimit(value string, defaultValue int, max, min int) (int, gtserror.WithCode) {
return parseInt(value, defaultValue, max, min, LimitKey)
i, err := parseInt(value, defaultValue, max, min, LimitKey)
if err != nil {
return 0, err
} else if i == 0 {
// treat 0 as an empty query
return defaultValue, nil
}
return i, nil
}

func ParseLocal(value string, defaultValue bool) (bool, gtserror.WithCode) {
Expand Down
14 changes: 10 additions & 4 deletions internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ func (c *Caches) setuphooks() {
})

c.GTS.EmojiCategory().SetInvalidateCallback(func(category *gtsmodel.EmojiCategory) {
// Invalidate entire emoji cache,
// as we can't know which emojis
// specifically this will effect.
c.GTS.Emoji().Clear()
// Invalidate any emoji in this category.
c.GTS.Emoji().Invalidate("CategoryID", category.ID)
})

c.GTS.Follow().SetInvalidateCallback(func(follow *gtsmodel.Follow) {
// Invalidate any related list entries.
c.GTS.ListEntry().Invalidate("FollowID", follow.ID)

// Invalidate follow origin account ID cached visibility.
c.Visibility.Invalidate("ItemID", follow.AccountID)
c.Visibility.Invalidate("RequesterID", follow.AccountID)
Expand All @@ -122,6 +123,11 @@ func (c *Caches) setuphooks() {
c.GTS.Follow().Invalidate("ID", followReq.ID)
})

c.GTS.List().SetInvalidateCallback(func(list *gtsmodel.List) {
// Invalidate all cached entries of this list.
c.GTS.ListEntry().Invalidate("ListID", list.ID)
})

c.GTS.Status().SetInvalidateCallback(func(status *gtsmodel.Status) {
// Invalidate status ID cached visibility.
c.Visibility.Invalidate("ItemID", status.ID)
Expand Down
3 changes: 3 additions & 0 deletions internal/cache/gts.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func (c *GTSCaches) initEmoji() {
{Name: "URI"},
{Name: "Shortcode.Domain"},
{Name: "ImageStaticURL"},
{Name: "CategoryID", Multi: true},
}, func(e1 *gtsmodel.Emoji) *gtsmodel.Emoji {
e2 := new(gtsmodel.Emoji)
*e2 = *e1
Expand Down Expand Up @@ -338,6 +339,8 @@ func (c *GTSCaches) initList() {
func (c *GTSCaches) initListEntry() {
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
Expand Down
Loading

0 comments on commit f431974

Please sign in to comment.