diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-30 15:37:27 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-30 15:37:27 -0400 |
| commit | 693cdde3273e0e8ffe1a04fd31fd54d982a3b1c4 (patch) | |
| tree | 50e5727566fbed62c84e62e888aca8717974c0d7 /packages/backend/src/core/ReactionService.ts | |
| parent | merge: apply more styles to our icons - fixes #1081 (!1069) (diff) | |
| download | sharkey-693cdde3273e0e8ffe1a04fd31fd54d982a3b1c4.tar.gz sharkey-693cdde3273e0e8ffe1a04fd31fd54d982a3b1c4.tar.bz2 sharkey-693cdde3273e0e8ffe1a04fd31fd54d982a3b1c4.zip | |
upsert reactions to avoid error+retry overhead
Diffstat (limited to 'packages/backend/src/core/ReactionService.ts')
| -rw-r--r-- | packages/backend/src/core/ReactionService.ts | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/packages/backend/src/core/ReactionService.ts b/packages/backend/src/core/ReactionService.ts index f05ee2ee73..e57a8d942d 100644 --- a/packages/backend/src/core/ReactionService.ts +++ b/packages/backend/src/core/ReactionService.ts @@ -176,27 +176,10 @@ export class ReactionService { reaction, }; - try { - await this.noteReactionsRepository.insert(record); - } catch (e) { - if (isDuplicateKeyValueError(e)) { - const exists = await this.noteReactionsRepository.findOneByOrFail({ - noteId: note.id, - userId: user.id, - }); - - if (exists.reaction !== reaction) { - // 別のリアクションがすでにされていたら置き換える - await this.delete(user, note); - await this.noteReactionsRepository.insert(record); - } else { - // 同じリアクションがすでにされていたらエラー - throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298'); - } - } else { - throw e; - } - } + await this.noteReactionsRepository.upsert(record, { + skipUpdateIfNoValuesChanged: true, + conflictPaths: ['noteId', 'userId'], + }); // Increment reactions count if (this.meta.enableReactionsBuffering) { |