Optimize machine pings query (#222)
* refactor recordPing method * optimize queries * migrate machine_pings remove id, serial_number add primary key on device_id add unique constraint on device_id * remove filelds from query, rename migration, delete duplicate migration * truncate machine_pings in migration
This commit is contained in:
parent
e7bb29341d
commit
13040f41a1
3 changed files with 22 additions and 12 deletions
|
|
@ -203,7 +203,7 @@ function plugins (settings, deviceId) {
|
|||
const tickerPromises = cryptoCodes.map(c => ticker.getRates(settings, fiatCode, c))
|
||||
const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c))
|
||||
const testnetPromises = cryptoCodes.map(c => wallet.cryptoNetwork(settings, c))
|
||||
const pingPromise = recordPing(serialNumber, deviceTime, deviceRec)
|
||||
const pingPromise = recordPing(deviceTime)
|
||||
const currentConfigVersionPromise = fetchCurrentConfigVersion()
|
||||
|
||||
const promises = [
|
||||
|
|
@ -236,19 +236,14 @@ function plugins (settings, deviceId) {
|
|||
return wallet.sendCoins(settings, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode)
|
||||
}
|
||||
|
||||
function recordPing (serialNumber, deviceTime, rec) {
|
||||
const machinePings = {
|
||||
id: uuid.v4(),
|
||||
device_id: deviceId,
|
||||
serial_number: serialNumber,
|
||||
device_time: deviceTime
|
||||
}
|
||||
function recordPing (deviceTime) {
|
||||
const devices = {
|
||||
last_online: deviceTime
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
db.none(pgp.helpers.insert(machinePings, null, 'machine_pings')),
|
||||
db.none(`insert into machine_pings(device_id, device_time) values($1, $2)
|
||||
ON CONFLICT (device_id) DO UPDATE SET device_time = $2`, [deviceId, deviceTime]),
|
||||
db.none(pgp.helpers.update(devices, null, 'devices') + 'WHERE device_id = ${deviceId}', { deviceId })
|
||||
])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue