fixes to recent database delete changes

This commit is contained in:
kim 2024-09-12 20:46:38 +01:00
commit 56589f9b2c
4 changed files with 34 additions and 31 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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)

View file

@ -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)