diff options
author | 2023-03-02 16:58:23 +0100 | |
---|---|---|
committer | 2023-03-02 16:58:23 +0100 | |
commit | bfccf4e450d22d9a3fc0c58d94ed728207d305e0 (patch) | |
tree | 4a96323881ffcff8af293f90370b9464ae044160 /internal/db/bundb/status.go | |
parent | [feature] Advertise rich text formats, support content_type field (#1370) (diff) | |
download | gotosocial-bfccf4e450d22d9a3fc0c58d94ed728207d305e0.tar.xz |
[bugfix] add ON CONFLICT statements to status updates (#1580)
Diffstat (limited to 'internal/db/bundb/status.go')
-rw-r--r-- | internal/db/bundb/status.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go index 8f1df2886..72e44068d 100644 --- a/internal/db/bundb/status.go +++ b/internal/db/bundb/status.go @@ -200,7 +200,9 @@ func (s *statusDB) PutStatus(ctx context.Context, status *gtsmodel.Status) db.Er Model(>smodel.StatusToEmoji{ StatusID: status.ID, EmojiID: i, - }).Exec(ctx); err != nil { + }). + On("CONFLICT (?, ?) DO NOTHING", bun.Ident("status_id"), bun.Ident("emoji_id")). + Exec(ctx); err != nil { err = s.conn.ProcessError(err) if !errors.Is(err, db.ErrAlreadyExists) { return err @@ -215,7 +217,9 @@ func (s *statusDB) PutStatus(ctx context.Context, status *gtsmodel.Status) db.Er Model(>smodel.StatusToTag{ StatusID: status.ID, TagID: i, - }).Exec(ctx); err != nil { + }). + On("CONFLICT (?, ?) DO NOTHING", bun.Ident("status_id"), bun.Ident("tag_id")). + Exec(ctx); err != nil { err = s.conn.ProcessError(err) if !errors.Is(err, db.ErrAlreadyExists) { return err @@ -261,7 +265,9 @@ func (s *statusDB) UpdateStatus(ctx context.Context, status *gtsmodel.Status, co Model(>smodel.StatusToEmoji{ StatusID: status.ID, EmojiID: i, - }).Exec(ctx); err != nil { + }). + On("CONFLICT (?, ?) DO NOTHING", bun.Ident("status_id"), bun.Ident("emoji_id")). + Exec(ctx); err != nil { err = s.conn.ProcessError(err) if !errors.Is(err, db.ErrAlreadyExists) { return err @@ -276,7 +282,9 @@ func (s *statusDB) UpdateStatus(ctx context.Context, status *gtsmodel.Status, co Model(>smodel.StatusToTag{ StatusID: status.ID, TagID: i, - }).Exec(ctx); err != nil { + }). + On("CONFLICT (?, ?) DO NOTHING", bun.Ident("status_id"), bun.Ident("tag_id")). + Exec(ctx); err != nil { err = s.conn.ProcessError(err) if !errors.Is(err, db.ErrAlreadyExists) { return err @@ -300,7 +308,7 @@ func (s *statusDB) UpdateStatus(ctx context.Context, status *gtsmodel.Status, co } } - // Finally, insert the status + // Finally, update the status _, err := tx. NewUpdate(). Model(status). |