mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
upsert reactions to avoid error+retry overhead
This commit is contained in:
parent
9637e1b82b
commit
693cdde327
1 changed files with 4 additions and 21 deletions
|
@ -176,28 +176,11 @@ export class ReactionService {
|
||||||
reaction,
|
reaction,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
await this.noteReactionsRepository.upsert(record, {
|
||||||
await this.noteReactionsRepository.insert(record);
|
skipUpdateIfNoValuesChanged: true,
|
||||||
} catch (e) {
|
conflictPaths: ['noteId', 'userId'],
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment reactions count
|
// Increment reactions count
|
||||||
if (this.meta.enableReactionsBuffering) {
|
if (this.meta.enableReactionsBuffering) {
|
||||||
await this.reactionsBufferingService.create(note.id, user.id, reaction, note.reactionAndUserPairCache);
|
await this.reactionsBufferingService.create(note.id, user.id, reaction, note.reactionAndUserPairCache);
|
||||||
|
|
Loading…
Add table
Reference in a new issue