summaryrefslogtreecommitdiff
path: root/internal/db/bundb/mention.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/mention.go')
-rw-r--r--internal/db/bundb/mention.go29
1 files changed, 19 insertions, 10 deletions
diff --git a/internal/db/bundb/mention.go b/internal/db/bundb/mention.go
index e64d6dac4..9a41eb3b8 100644
--- a/internal/db/bundb/mention.go
+++ b/internal/db/bundb/mention.go
@@ -19,6 +19,7 @@ package bundb
import (
"context"
+ "errors"
"fmt"
"github.com/superseriousbusiness/gotosocial/internal/db"
@@ -109,16 +110,24 @@ func (m *mentionDB) PutMention(ctx context.Context, mention *gtsmodel.Mention) e
}
func (m *mentionDB) DeleteMentionByID(ctx context.Context, id string) error {
- if _, err := m.conn.
- NewDelete().
- Table("mentions").
- Where("? = ?", bun.Ident("id"), id).
- Exec(ctx); err != nil {
- return m.conn.ProcessError(err)
- }
+ defer m.state.Caches.GTS.Mention().Invalidate("ID", id)
- // Invalidate mention from the lookup cache.
- m.state.Caches.GTS.Mention().Invalidate("ID", id)
+ // Load mention into cache before attempting a delete,
+ // as we need it cached in order to trigger the invalidate
+ // callback. This in turn invalidates others.
+ _, err := m.GetMention(gtscontext.SetBarebones(ctx), id)
+ if err != nil {
+ if errors.Is(err, db.ErrNoEntries) {
+ // not an issue.
+ err = nil
+ }
+ return err
+ }
- return nil
+ // Finally delete mention from DB.
+ _, err = m.conn.NewDelete().
+ Table("mentions").
+ Where("? = ?", bun.Ident("id"), id).
+ Exec(ctx)
+ return m.conn.ProcessError(err)
}