Skip to content

Commit

Permalink
do nothing when conflict on insert new user
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgauthier committed Jan 26, 2019
1 parent b643658 commit 0f2dac8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/client/registry/UserRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class UserRegistry extends Map {

const inserted = await this.database.users.add(member);

this.cacheUser(inserted);
if (inserted)
this.cacheUser(inserted);
else
Log.warn(`Adding new user from member ${Format.member(member)}, user was already inserted.`);
}

async ignoreUser(user, ignoreUntil) {
Expand Down
3 changes: 2 additions & 1 deletion src/database/repositories/UserRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class UserRepository {
try {
return await this._db.tx(async t => {
const inserted = await t.one(
'INSERT INTO users.users (user_id, is_bot) VALUES ($[user_id], $[is_bot]) RETURNING *;',
`INSERT INTO users.users (user_id, is_bot) VALUES ($[user_id], $[is_bot])
ON CONFLICT(user_id) DO NOTHING RETURNING *;`,
{ user_id: user.id, is_bot: !!user.bot }
);
await t.none(
Expand Down

0 comments on commit 0f2dac8

Please sign in to comment.