diff options
Diffstat (limited to 'internal/db/bundb/status.go')
-rw-r--r-- | internal/db/bundb/status.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go index e247e8940..59417afe4 100644 --- a/internal/db/bundb/status.go +++ b/internal/db/bundb/status.go @@ -227,6 +227,42 @@ func (s *statusDB) UpdateStatus(ctx context.Context, status *gtsmodel.Status) (* return status, err } +func (s *statusDB) DeleteStatusByID(ctx context.Context, id string) db.Error { + err := s.conn.RunInTx(ctx, func(tx bun.Tx) error { + // delete links between this status and any emojis it uses + if _, err := tx. + NewDelete(). + Model(>smodel.StatusToEmoji{}). + Where("status_id = ?", bun.Ident(id)). + Exec(ctx); err != nil { + return err + } + + // delete links between this status and any tags it uses + if _, err := tx. + NewDelete(). + Model(>smodel.StatusToTag{}). + Where("status_id = ?", bun.Ident(id)). + Exec(ctx); err != nil { + return err + } + + // delete the status itself + if _, err := tx. + NewDelete(). + Model(>smodel.Status{ID: id}). + WherePK(). + Exec(ctx); err != nil { + return err + } + + s.cache.Invalidate(id) + return nil + }) + + return s.conn.ProcessError(err) +} + func (s *statusDB) GetStatusParents(ctx context.Context, status *gtsmodel.Status, onlyDirect bool) ([]*gtsmodel.Status, db.Error) { parents := []*gtsmodel.Status{} s.statusParent(ctx, status, &parents, onlyDirect) |