add appropriate invalidate hooks

This commit is contained in:
kim 2024-04-15 12:27:30 +01:00
parent 87ced01716
commit 511a556cb2
3 changed files with 19 additions and 7 deletions

14
internal/cache/db.go vendored
View file

@ -315,9 +315,10 @@ func (c *Caches) initApplication() {
{Fields: "ID"},
{Fields: "ClientID"},
},
MaxSize: cap,
IgnoreErr: ignoreErrors,
Copy: copyF,
MaxSize: cap,
IgnoreErr: ignoreErrors,
Copy: copyF,
Invalidate: c.OnInvalidateApplication,
})
}
@ -399,9 +400,10 @@ func (c *Caches) initClient() {
Indices: []structr.IndexConfig{
{Fields: "ID"},
},
MaxSize: cap,
IgnoreErr: ignoreErrors,
Copy: copyF,
MaxSize: cap,
IgnoreErr: ignoreErrors,
Copy: copyF,
Invalidate: c.OnInvalidateClient,
})
}

View file

@ -60,6 +60,11 @@ func (c *Caches) OnInvalidateAccount(account *gtsmodel.Account) {
c.GTS.Move.Invalidate("TargetURI", account.URI)
}
func (c *Caches) OnInvalidateApplication(app *gtsmodel.Application) {
// Invalidate cached client of this application.
c.GTS.Client.Invalidate("ID", app.ClientID)
}
func (c *Caches) OnInvalidateBlock(block *gtsmodel.Block) {
// Invalidate block origin account ID cached visibility.
c.Visibility.Invalidate("ItemID", block.AccountID)
@ -73,6 +78,11 @@ func (c *Caches) OnInvalidateBlock(block *gtsmodel.Block) {
c.GTS.BlockIDs.Invalidate(block.AccountID)
}
func (c *Caches) OnInvalidateClient(client *gtsmodel.Client) {
// Invalidate any tokens under this client.
c.GTS.Token.Invalidate("ClientID", client.ID)
}
func (c *Caches) OnInvalidateEmojiCategory(category *gtsmodel.EmojiCategory) {
// Invalidate any emoji in this category.
c.GTS.Emoji.Invalidate("CategoryID", category.ID)

View file

@ -75,7 +75,7 @@ func (p *Processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *api
}
// chuck it in the db
if err := p.state.DB.Put(ctx, oc); err != nil {
if err := p.state.DB.PutClient(ctx, oc); err != nil {
return nil, gtserror.NewErrorInternalError(err)
}