From 56589f9b2cd08e0a75cb192641a2a8ee7c328199 Mon Sep 17 00:00:00 2001 From: kim Date: Thu, 12 Sep 2024 20:46:38 +0100 Subject: [PATCH] fixes to recent database delete changes --- internal/db/bundb/relationship_block.go | 14 +++++------- internal/db/bundb/relationship_follow.go | 23 ++++++++++++++------ internal/db/bundb/relationship_follow_req.go | 17 +++++++-------- internal/db/bundb/relationship_mute.go | 11 ++++------ 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/internal/db/bundb/relationship_block.go b/internal/db/bundb/relationship_block.go index 586a67f29..9738970e5 100644 --- a/internal/db/bundb/relationship_block.go +++ b/internal/db/bundb/relationship_block.go @@ -228,7 +228,8 @@ func (r *relationshipDB) DeleteBlockByID(ctx context.Context, id string) error { bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -254,7 +255,8 @@ func (r *relationshipDB) DeleteBlockByURI(ctx context.Context, uri string) error bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -286,15 +288,11 @@ func (r *relationshipDB) DeleteAccountBlocks(ctx context.Context, accountID stri bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } - // Check for deletions. - if len(deleted) == 0 { - return nil - } - // Invalidate all account's incoming / outoing blocks. r.state.Caches.DB.Block.Invalidate("AccountID", accountID) r.state.Caches.DB.Block.Invalidate("TargetAccountID", accountID) diff --git a/internal/db/bundb/relationship_follow.go b/internal/db/bundb/relationship_follow.go index 714ece975..bb2c14cbb 100644 --- a/internal/db/bundb/relationship_follow.go +++ b/internal/db/bundb/relationship_follow.go @@ -264,7 +264,8 @@ func (r *relationshipDB) DeleteFollow( Where("? = ?", bun.Ident("account_id"), sourceAccountID). Where("? = ?", bun.Ident("target_account_id"), targetAccountID). Returning("?", bun.Ident("id")). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -297,7 +298,8 @@ func (r *relationshipDB) DeleteFollowByID(ctx context.Context, id string) error bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -329,7 +331,8 @@ func (r *relationshipDB) DeleteFollowByURI(ctx context.Context, uri string) erro bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -367,13 +370,19 @@ func (r *relationshipDB) DeleteAccountFollows(ctx context.Context, accountID str bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } - // Check for deletions. - if len(deleted) == 0 { - return nil + // Gather the follow IDs that were deleted for removing related list entries. + followIDs := util.Gather(nil, deleted, func(follow *gtsmodel.Follow) string { + return follow.ID + }) + + // Delete every list entry that was created targetting any of these follow IDs. + if err := r.state.DB.DeleteAllListEntriesByFollowIDs(ctx, followIDs...); err != nil { + return gtserror.Newf("error deleting list entries: %w", err) } // Invalidate all account's incoming / outoing follows. diff --git a/internal/db/bundb/relationship_follow_req.go b/internal/db/bundb/relationship_follow_req.go index f2526103c..4ae156ab7 100644 --- a/internal/db/bundb/relationship_follow_req.go +++ b/internal/db/bundb/relationship_follow_req.go @@ -306,7 +306,8 @@ func (r *relationshipDB) DeleteFollowRequest( Where("? = ?", bun.Ident("account_id"), sourceAccountID). Where("? = ?", bun.Ident("target_account_id"), targetAccountID). Returning("?", bun.Ident("id")). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -334,7 +335,8 @@ func (r *relationshipDB) DeleteFollowRequestByID(ctx context.Context, id string) bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -361,7 +363,8 @@ func (r *relationshipDB) DeleteFollowRequestByURI(ctx context.Context, uri strin bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -394,15 +397,11 @@ func (r *relationshipDB) DeleteAccountFollowRequests(ctx context.Context, accoun bun.Ident("account_id"), bun.Ident("target_account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } - // Check for deletions. - if len(deleted) == 0 { - return nil - } - // Invalidate all account's incoming / outoing follows requests. r.state.Caches.DB.FollowRequest.Invalidate("AccountID", accountID) r.state.Caches.DB.FollowRequest.Invalidate("TargetAccountID", accountID) diff --git a/internal/db/bundb/relationship_mute.go b/internal/db/bundb/relationship_mute.go index 65821b808..37d97a64f 100644 --- a/internal/db/bundb/relationship_mute.go +++ b/internal/db/bundb/relationship_mute.go @@ -212,7 +212,8 @@ func (r *relationshipDB) DeleteMuteByID(ctx context.Context, id string) error { Model(&deleted). Where("? = ?", bun.Ident("id"), id). Returning("?", bun.Ident("account_id")). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } @@ -243,15 +244,11 @@ func (r *relationshipDB) DeleteAccountMutes(ctx context.Context, accountID strin Returning("?", bun.Ident("account_id"), ). - Exec(ctx); err != nil { + Exec(ctx); err != nil && + !errors.Is(err, db.ErrNoEntries) { return err } - // Check for deletions. - if len(deleted) == 0 { - return nil - } - // Invalidate all account's incoming / outoing user mutes. r.state.Caches.DB.UserMute.Invalidate("AccountID", accountID) r.state.Caches.DB.UserMute.Invalidate("TargetAccountID", accountID)