sharding (general): Add launch data filters.

Filter cached reaction role messages by shardid.
Filter expiring rented room by shardid.
Filter scanned study badges by shardid.
Filter resumed study sessions by shardid.
Filter resumed workouts by shardid.

Fix a spacing issue in the log printer.
This commit is contained in:
2021-12-22 17:26:49 +02:00
parent 25e22c07d0
commit 276886a3a7
6 changed files with 18 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ from discord import PartialEmoji
from meta import client
from core import Lion
from data import Row
from data.conditions import THIS_SHARD
from utils.lib import utc_now
from settings import GuildSettings
@@ -584,5 +585,5 @@ def load_reaction_roles(client):
"""
Load the ReactionRoleMessages.
"""
rows = reaction_role_messages.fetch_rows_where()
rows = reaction_role_messages.fetch_rows_where(guildid=THIS_SHARD)
ReactionRoleMessage._messages = {row.messageid: ReactionRoleMessage(row.messageid) for row in rows}

View File

@@ -5,6 +5,7 @@ import datetime
from cmdClient.lib import SafeCancellation
from meta import client
from data.conditions import THIS_SHARD
from settings import GuildSettings
from .data import rented, rented_members
@@ -276,7 +277,7 @@ class Room:
@module.launch_task
async def load_rented_rooms(client):
rows = rented.fetch_rows_where()
rows = rented.fetch_rows_where(guildid=THIS_SHARD)
for row in rows:
Room(row.channelid).schedule()
client.log(

View File

@@ -6,8 +6,8 @@ import contextlib
import discord
from meta import client
from data.conditions import GEQ
from meta import client, sharding
from data.conditions import GEQ, THIS_SHARD
from core.data import lions
from utils.lib import strfdur
from settings import GuildSettings
@@ -54,12 +54,16 @@ async def update_study_badges(full=False):
# Retrieve member rows with out of date study badges
if not full and client.appdata.last_study_badge_scan is not None:
# TODO: _extra here is a hack to cover for inflexible conditionals
update_rows = new_study_badges.select_where(
guildid=THIS_SHARD,
_timestamp=GEQ(client.appdata.last_study_badge_scan or 0),
_extra="OR session_start IS NOT NULL"
_extra="OR session_start IS NOT NULL AND (guildid >> 22) %% {} = {}".format(
sharding.shard_count, sharding.shard_number
)
)
else:
update_rows = new_study_badges.select_where()
update_rows = new_study_badges.select_where(guildid=THIS_SHARD)
if not update_rows:
client.appdata.last_study_badge_scan = datetime.datetime.utcnow()

View File

@@ -7,6 +7,7 @@ from collections import defaultdict
from utils.lib import utc_now
from data import tables
from data.conditions import THIS_SHARD
from core import Lion
from meta import client
@@ -398,7 +399,7 @@ async def _init_session_tracker(client):
ended = 0
# Grab all ongoing sessions from data
rows = current_sessions.fetch_rows_where()
rows = current_sessions.fetch_rows_where(guildid=THIS_SHARD)
# Iterate through, resume or end as needed
for row in rows:

View File

@@ -7,6 +7,7 @@ from core import Lion
from settings import GuildSettings
from meta import client
from data import NULL, tables
from data.conditions import THIS_SHARD
from .module import module
from .data import workout_sessions
@@ -226,7 +227,8 @@ async def load_workouts(client):
client.objects['current_workouts'] = {} # (guildid, userid) -> Row
# Process any incomplete workouts
workouts = workout_sessions.fetch_rows_where(
duration=NULL
duration=NULL,
guildid=THIS_SHARD
)
count = 0
for workout in workouts: