Skip to content

Commit

Permalink
Fix: 同じNoteを同タイミングで取得すると失敗する
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Apr 28, 2019
1 parent f5de353 commit 101d1d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/services/note/create.ts
Expand Up @@ -517,9 +517,17 @@ async function insertNote(user: IUser, data: Option, tags: string[], emojis: str
} catch (e) {
// duplicate key error
if (e.code === 11000) {
return null;
if (insert.uri != null) {
const n = await Note.findOne({ uri: insert.uri });
if (n) {
console.warn(`duplicated insert: ${n.uri}`);
return n;
}
}
}

console.error(e);

throw 'something happened';
}
}
Expand Down

0 comments on commit 101d1d9

Please sign in to comment.