Fix: do things in the right order
This commit is contained in:
parent
78697b860d
commit
a74081fefd
|
@ -27,11 +27,12 @@ async function getOnlineDevices() {
|
|||
}
|
||||
|
||||
async function updateDevicesStatus() {
|
||||
const lastSeenThreshold = subMinutes(new Date(), RECENT_THRESHOLD_IN_MINUTES)
|
||||
|
||||
const recent = prisma.wifiDevice.updateMany({
|
||||
where: {
|
||||
status: 'OFFLINE',
|
||||
lastSeen: {
|
||||
gt: subMinutes(new Date(), RECENT_THRESHOLD_IN_MINUTES)
|
||||
gt: lastSeenThreshold
|
||||
}
|
||||
},
|
||||
data: {
|
||||
|
@ -42,7 +43,7 @@ async function updateDevicesStatus() {
|
|||
const offline = prisma.wifiDevice.updateMany({
|
||||
where: {
|
||||
lastSeen: {
|
||||
lte: subMinutes(new Date(), RECENT_THRESHOLD_IN_MINUTES)
|
||||
lte: lastSeenThreshold
|
||||
}
|
||||
},
|
||||
data: {
|
||||
|
@ -111,10 +112,10 @@ async function updateDevicesInfo() {
|
|||
try {
|
||||
const onlineDevices = await getOnlineDevices()
|
||||
|
||||
await updateDB(onlineDevices)
|
||||
|
||||
await updateDevicesStatus()
|
||||
|
||||
await updateDB(onlineDevices)
|
||||
|
||||
pubsub.publish(USER_PRESENCE_UPDATED, {
|
||||
userPresenceUpdated: onlineDevices.length
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user