diff options
Diffstat (limited to 'internal/db/bundb/account.go')
-rw-r--r-- | internal/db/bundb/account.go | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index 56d46a232..f7e243f47 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -302,7 +302,7 @@ func (a *accountDB) UpdateAccount(ctx context.Context, account *gtsmodel.Account columns = append(columns, "updated_at") } - err := a.state.Caches.GTS.Account().Store(account, func() error { + return a.state.Caches.GTS.Account().Store(account, func() error { // It is safe to run this database transaction within cache.Store // as the cache does not attempt a mutex lock until AFTER hook. // @@ -338,15 +338,23 @@ func (a *accountDB) UpdateAccount(ctx context.Context, account *gtsmodel.Account return err }) }) - if err != nil { - return err - } - - return nil } func (a *accountDB) DeleteAccount(ctx context.Context, id string) db.Error { - if err := a.conn.RunInTx(ctx, func(tx bun.Tx) error { + defer a.state.Caches.GTS.Account().Invalidate("ID", id) + + // Load account into cache before attempting a delete, + // as we need it cached in order to trigger the invalidate + // callback. This in turn invalidates others. + _, err := a.GetAccountByID(gtscontext.SetBarebones(ctx), id) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + // NOTE: even if db.ErrNoEntries is returned, we + // still run the below transaction to ensure related + // objects are appropriately deleted. + return err + } + + return a.conn.RunInTx(ctx, func(tx bun.Tx) error { // clear out any emoji links if _, err := tx. NewDelete(). @@ -363,14 +371,7 @@ func (a *accountDB) DeleteAccount(ctx context.Context, id string) db.Error { Where("? = ?", bun.Ident("account.id"), id). Exec(ctx) return err - }); err != nil { - return err - } - - // Invalidate account from database lookups. - a.state.Caches.GTS.Account().Invalidate("ID", id) - - return nil + }) } func (a *accountDB) GetAccountLastPosted(ctx context.Context, accountID string, webOnly bool) (time.Time, db.Error) { |