fix online count

master
Aevann1 2022-08-13 12:05:27 +02:00
parent edc44c62b4
commit dd6f86ce31
1 changed files with 2 additions and 6 deletions

View File

@ -91,9 +91,7 @@ def connect(v):
if v.username not in online: if v.username not in online:
online.append(v.username) online.append(v.username)
emit("online", online, broadcast=True) emit("online", online, broadcast=True)
online_count = cache.get(f'{SITE}_online') or 0 cache.set(f'{SITE}_online', len(online))
online_count += 1
cache.set(f'{SITE}_online', online_count)
emit('typing', typing) emit('typing', typing)
return '', 204 return '', 204
@ -104,9 +102,7 @@ def disconnect(v):
if v.username in online: if v.username in online:
online.remove(v.username) online.remove(v.username)
emit("online", online, broadcast=True) emit("online", online, broadcast=True)
online_count = cache.get(f'{SITE}_online') or 1 cache.set(f'{SITE}_online', len(online))
online_count -= 1
cache.set(f'{SITE}_online', online_count)
if v.username in typing: typing.remove(v.username) if v.username in typing: typing.remove(v.username)
emit('typing', typing, broadcast=True) emit('typing', typing, broadcast=True)