Merge branch 'utils' into python-rewrite

This commit is contained in:
2021-10-05 11:21:30 +03:00
2 changed files with 12 additions and 13 deletions

View File

@@ -168,7 +168,7 @@ async def turnover():
to_update = [ to_update = [
(mem.data.duration + int((now - mem.data.last_joined_at).total_seconds()), None, mem.slotid, mem.userid) (mem.data.duration + int((now - mem.data.last_joined_at).total_seconds()), None, mem.slotid, mem.userid)
for slot in last_slots for mem in slot.members.values() for slot in last_slots for mem in slot.members.values()
if mem.data.last_joined_at if mem.data and mem.data.last_joined_at
] ]
if to_update: if to_update:
accountability_members.update_many( accountability_members.update_many(
@@ -178,6 +178,15 @@ async def turnover():
cast_row='(NULL::int, NULL::timestamptz, NULL::int, NULL::int)' cast_row='(NULL::int, NULL::timestamptz, NULL::int, NULL::int)'
) )
# Close all completed rooms, update data
await asyncio.gather(*(slot.close() for slot in last_slots), return_exceptions=True)
update_slots = [slot.data.slotid for slot in last_slots if slot.data]
if update_slots:
accountability_rooms.update_where(
{'closed_at': utc_now()},
slotid=update_slots
)
# Rotate guild sessions # Rotate guild sessions
[aguild.advance() for aguild in AccountabilityGuild.cache.values()] [aguild.advance() for aguild in AccountabilityGuild.cache.values()]
@@ -185,7 +194,6 @@ async def turnover():
# We could break up the session starting? # We could break up the session starting?
# Move members of the next session over to the session channel # Move members of the next session over to the session channel
# This includes any members of the session just complete
current_slots = [ current_slots = [
aguild.current_slot for aguild in AccountabilityGuild.cache.values() aguild.current_slot for aguild in AccountabilityGuild.cache.values()
if aguild.current_slot is not None if aguild.current_slot is not None
@@ -207,21 +215,12 @@ async def turnover():
return_exceptions=True return_exceptions=True
) )
# Close all completed rooms, update data
await asyncio.gather(*(slot.close() for slot in last_slots))
update_slots = [slot.data.slotid for slot in last_slots if slot.data]
if update_slots:
accountability_rooms.update_where(
{'closed_at': utc_now()},
slotid=update_slots
)
# Update session data of all members in new channels # Update session data of all members in new channels
member_session_data = [ member_session_data = [
(0, slot.start_time, mem.slotid, mem.userid) (0, slot.start_time, mem.slotid, mem.userid)
for slot in current_slots for slot in current_slots
for mem in slot.members.values() for mem in slot.members.values()
if mem.member.voice and mem.member.voice.channel == slot.channel if mem.data and mem.member and mem.member.voice and mem.member.voice.channel == slot.channel
] ]
if member_session_data: if member_session_data:
accountability_members.update_many( accountability_members.update_many(

View File

@@ -2,4 +2,4 @@ from .module import module
from . import guild_config from . import guild_config
from . import statreset from . import statreset
from . import utils from . import new_members