fix (schedule): Various bug fixes.

This commit is contained in:
2023-06-30 12:34:21 +03:00
parent a7c5af59a7
commit 65c17f11b2
3 changed files with 20 additions and 15 deletions

View File

@@ -489,7 +489,8 @@ class ScheduleCog(LionCog):
session = slot.sessions.get(guildid, None) session = slot.sessions.get(guildid, None)
if session is None: if session is None:
# Create a new session in the slot and set it up # Create a new session in the slot and set it up
session = await slot.load_sessions(session_data[guildid, slotid]) sessions = await slot.load_sessions([session_data[guildid, slotid]])
session = sessions[guildid]
slot.sessions[guildid] = session slot.sessions[guildid] = session
if slot.closing.is_set(): if slot.closing.is_set():
# This should never happen # This should never happen

View File

@@ -210,20 +210,21 @@ class TimeSlot:
await batchrun_per_second(coros, 5) await batchrun_per_second(coros, 5)
# Save messageids # Save messageids
tmptable = TemporaryTable( if sessions:
'_gid', '_sid', '_mid', tmptable = TemporaryTable(
types=('BIGINT', 'INTEGER', 'BIGINT') '_gid', '_sid', '_mid',
) types=('BIGINT', 'INTEGER', 'BIGINT')
tmptable.values = [ )
(sg.data.guildid, sg.data.slotid, sg.messageid) tmptable.values = [
for sg in sessions (sg.data.guildid, sg.data.slotid, sg.messageid)
if sg.messageid is not None for sg in sessions
] if sg.messageid is not None
await Data.ScheduleSession.table.update_where( ]
guildid=tmptable['_gid'], slotid=tmptable['_sid'] await Data.ScheduleSession.table.update_where(
).set( guildid=tmptable['_gid'], slotid=tmptable['_sid']
messageid=tmptable['_mid'] ).set(
).from_expr(tmptable) messageid=tmptable['_mid']
).from_expr(tmptable)
except Exception: except Exception:
logger.exception( logger.exception(
f"Unhandled exception while preparing timeslot <slotid: {self.slotid}>." f"Unhandled exception while preparing timeslot <slotid: {self.slotid}>."

View File

@@ -123,6 +123,9 @@ class TemporaryTable(Expression):
AS AS
name (col1, col2) name (col1, col2)
""" """
if not self.values:
raise ValueError("Cannot flatten CTE with no values.")
single_value = sql.SQL("({})").format(sql.SQL(", ").join(sql.Placeholder() for _ in self.columns)) single_value = sql.SQL("({})").format(sql.SQL(", ").join(sql.Placeholder() for _ in self.columns))
if self.types: if self.types:
first_value = sql.SQL("({})").format( first_value = sql.SQL("({})").format(