Skip to content

Commit

Permalink
performance(server): optimized automatic unarming hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
TyIsI committed Dec 29, 2024
1 parent e820ddb commit 625daaa
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions server/lib/stores/devices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ const debug = require('debug')('tacos:lib:stores:devices')

const { config } = require('../../config/')
const { prisma } = require('../../db/prisma')
const { coerceMilliseconds } = require('../../utils')

const DeviceStore = function () {
this.devices = prisma.devices

if (this.devices == null) throw new Error('Missing devices')

setInterval(() => {
debug('Autodisarming')
this.automaticDisarm()
}, 5000)
this.automaticDisarm()
}

DeviceStore.prototype.automaticDisarm = async function () {
Expand Down Expand Up @@ -118,10 +116,19 @@ DeviceStore.prototype.armDevice = async function (deviceId) {
where: { id: deviceId },
data: {
armed: 1,
activation_expiry: Date.now() + Number(config.activation_timeout)
activation_expiry:
Date.now() +
coerceMilliseconds(Number(config.activation_timeout))
}
})

setTimeout(
() => {
void this.unarmDevice(deviceId)
},
coerceMilliseconds(Number(config.activation_timeout))
)

return this.getDeviceDetails(deviceId)
}

Expand Down

0 comments on commit 625daaa

Please sign in to comment.