From eb860d78b836d810f7c29d5587e17321adf20bef Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 13 Jan 2021 14:21:47 -0800 Subject: add some more transaction locks --- lib/account.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'lib/account.js') diff --git a/lib/account.js b/lib/account.js index 931638e0..5a8c3924 100644 --- a/lib/account.js +++ b/lib/account.js @@ -1,16 +1,15 @@ const axios = require("axios"); module.exports = async (asset, user, transaction) => { - const account = await db.Account.findOne( - { - where: { - user_id: user.id, - asset, - pubkey: null - } + const account = await db.Account.findOne({ + where: { + user_id: user.id, + asset, + pubkey: null }, - { transaction } - ); + lock: transaction.LOCK.UPDATE, + transaction + }); if (account) return account; @@ -28,13 +27,16 @@ module.exports = async (asset, user, transaction) => { if (assets[asset]) { ({ domain, ticker, precision, name } = assets[asset]); } else { - const existing = await db.Account.findOne({ - where: { - asset + const existing = await db.Account.findOne( + { + where: { + asset + }, + order: [["id", "ASC"]], + limit: 1 }, - order: [["id", "ASC"]], - limit: 1, - }, { transaction }); + { transaction } + ); if (existing) { ({ domain, ticker, precision, name } = existing); -- cgit v1.2.3