Skip to content

Commit c0d5566

Browse files
Make sure no userhistory exists before initializing it (#15415)
1 parent ded71b4 commit c0d5566

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: website/server/models/user/hooks.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,13 @@ schema.pre('save', true, async function preSaveUser (next, done) {
365365
}
366366
if (!this.flags.initializedUserHistory) {
367367
this.flags.initializedUserHistory = true;
368-
const history = UserHistory();
369-
history.userId = this._id;
370-
await history.save();
368+
// Ensure that it does not try to create a new history if it already exists
369+
const existingHistory = await UserHistory.findOne({ userId: this._id });
370+
if (!existingHistory) {
371+
const history = UserHistory();
372+
history.userId = this._id;
373+
await history.save();
374+
}
371375
}
372376
}
373377

0 commit comments

Comments
 (0)