summaryrefslogtreecommitdiff
path: root/internal/processing/fromcommon.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-05-18 23:13:03 +0200
committerLibravatar GitHub <noreply@github.com>2022-05-18 22:13:03 +0100
commitb2810fedf201dc9ae80ea8ec6d48e5cf7e21e6ea (patch)
treea6d7c2b7f349d72a383a7124e796c746c6a37111 /internal/processing/fromcommon.go
parent[performance] Add further indexes to mitigate laggy queries (#586) (diff)
downloadgotosocial-b2810fedf201dc9ae80ea8ec6d48e5cf7e21e6ea.tar.xz
[bugfix] Clean up boosts of status when the status itself is deleted (#579)
* move status wiping logic to fromcommon.go * delete reblogs of status when a status is deleted * add admin boost of zork to test model * update tests to make them more determinate * Merge branch 'main' into status_reblog_cleanup * move status wiping logic to fromcommon.go * delete reblogs of status when a status is deleted * add admin boost of zork to test model * update tests to make them more determinate * Merge branch 'main' into status_reblog_cleanup * test status delete via client api * go fmt
Diffstat (limited to 'internal/processing/fromcommon.go')
-rw-r--r--internal/processing/fromcommon.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/processing/fromcommon.go b/internal/processing/fromcommon.go
index 1b470918d..e9a2e4994 100644
--- a/internal/processing/fromcommon.go
+++ b/internal/processing/fromcommon.go
@@ -441,3 +441,47 @@ func (p *processor) deleteStatusFromTimelines(ctx context.Context, status *gtsmo
return p.streamingProcessor.StreamDelete(status.ID)
}
+
+// wipeStatus contains common logic used to totally delete a status
+// + all its attachments, notifications, boosts, and timeline entries.
+func (p *processor) wipeStatus(ctx context.Context, statusToDelete *gtsmodel.Status) error {
+ // delete all attachments for this status
+ for _, a := range statusToDelete.AttachmentIDs {
+ if err := p.mediaProcessor.Delete(ctx, a); err != nil {
+ return err
+ }
+ }
+
+ // delete all mentions for this status
+ for _, m := range statusToDelete.MentionIDs {
+ if err := p.db.DeleteByID(ctx, m, &gtsmodel.Mention{}); err != nil {
+ return err
+ }
+ }
+
+ // delete all notifications for this status
+ if err := p.db.DeleteWhere(ctx, []db.Where{{Key: "status_id", Value: statusToDelete.ID}}, &[]*gtsmodel.Notification{}); err != nil {
+ return err
+ }
+
+ // delete all boosts for this status + remove them from timelines
+ boosts, err := p.db.GetStatusReblogs(ctx, statusToDelete)
+ if err != nil {
+ return err
+ }
+ for _, b := range boosts {
+ if err := p.deleteStatusFromTimelines(ctx, b); err != nil {
+ return err
+ }
+ if err := p.db.DeleteByID(ctx, b.ID, b); err != nil {
+ return err
+ }
+ }
+
+ // delete this status from any and all timelines
+ if err := p.deleteStatusFromTimelines(ctx, statusToDelete); err != nil {
+ return err
+ }
+
+ return nil
+}