Refactor
This commit is contained in:
parent
686e276163
commit
c605734d8f
|
@ -31,16 +31,7 @@ async function setAllDevicesAsOffline() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateDevicesInfo() {
|
async function updateDB(onlineDevices) {
|
||||||
if (working) return -1 // Debounce updates
|
|
||||||
|
|
||||||
working = true
|
|
||||||
|
|
||||||
try {
|
|
||||||
const onlineDevices = await getOnlineDevices()
|
|
||||||
|
|
||||||
await setAllDevicesAsOffline()
|
|
||||||
|
|
||||||
for (const device of onlineDevices) {
|
for (const device of onlineDevices) {
|
||||||
if (!device.user)
|
if (!device.user)
|
||||||
await prisma.$executeRaw(
|
await prisma.$executeRaw(
|
||||||
|
@ -72,6 +63,19 @@ async function updateDevicesInfo() {
|
||||||
console.log('[wifiDevice upsert error]', e)
|
console.log('[wifiDevice upsert error]', e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateDevicesInfo() {
|
||||||
|
if (working) return -1 // Debounce updates
|
||||||
|
|
||||||
|
working = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const onlineDevices = await getOnlineDevices()
|
||||||
|
|
||||||
|
await setAllDevicesAsOffline()
|
||||||
|
|
||||||
|
await updateDB(onlineDevices)
|
||||||
|
|
||||||
pubsub.publish(USER_PRESENCE_UPDATED, {
|
pubsub.publish(USER_PRESENCE_UPDATED, {
|
||||||
userPresenceUpdated: onlineDevices.length
|
userPresenceUpdated: onlineDevices.length
|
||||||
|
|
Loading…
Reference in New Issue
Block a user