Skip to content

Commit

Permalink
improve perf of last seen updating
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jul 27, 2024
1 parent cf1df89 commit bd1b4ba
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions bot/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,23 @@ async function updateLastSeen() {

const now = Date.now()

ops.forEach((op: SeenPlayer) => {
for (const op of ops) {
const seen = lastSeenPlayers.get(op.name)

if (!op.transitions) op.transitions = 0
if (!seen?.online) op.transitions++
if (!op['transitions']) op['transitions'] = 0
if (!seen?.online) op['transitions']++

op.timestamp = now
op['timestamp'] = now

lastSeenPlayers.set(op.name, op)
})
lastSeenPlayers.set(op.name, op as SeenPlayer)
}

lastSeenPlayers.forEach(v => {
v.online = ops.some(op => op.name == v.name)
})
const opNames = new Set(ops.map(op => op.name))
for (const p of lastSeenPlayers.values()) {
p.online = opNames.has(p.name)
}

console.log(`[AURORA] Updated last seen. Length: ${lastSeenPlayers.size}`)
//console.log(`[AURORA] Updated last seen. Length: ${lastSeenPlayers.size}`)
}
//#endregion

Expand Down

0 comments on commit bd1b4ba

Please sign in to comment.