From aea2e0beb3a1ecc953f150cb03db00f3a5530bdd Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Fri, 2 Dec 2022 18:27:50 -0500 Subject: [PATCH] Remove subqueries when sending to IN call. --- cogs/commands/data_management.py | 4 ++-- utilities/utils.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cogs/commands/data_management.py b/cogs/commands/data_management.py index 3d819b9..2049c34 100644 --- a/cogs/commands/data_management.py +++ b/cogs/commands/data_management.py @@ -85,7 +85,7 @@ class DataManagementCog(commands.Cog, name="Table Management"): for group in session.scalars(stmt): await send_highscore_message(interaction.guild.get_channel(group.ChannelId), group) - await interaction.send(f'User "{user_name}" was removed from all tables.') + await interaction.send(f'User "{user_name}" was removed from all tables.', ephemeral=True) @user.subcommand(description="Deletes a user's scores from a category.") async def from_category( @@ -140,7 +140,7 @@ class DataManagementCog(commands.Cog, name="Table Management"): stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id)) group = session.scalar(stmt) - category_ids = select(Category.CategoryId).where(Category.GroupId == int(group_id)).subquery() + category_ids = select(Category.CategoryId).where(Category.GroupId == int(group_id)) stmt = select(Score).where(Score.CategoryId.in_(category_ids)).where(Score.UserName == user_name) for score in session.scalars(stmt): diff --git a/utilities/utils.py b/utilities/utils.py index dd30f44..a194968 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -109,7 +109,7 @@ def autofill_users_in_group_category(guild_id: int, group_id: int, category_id: # If no category id, get all users in group. if category_id == 0: - subq = select(Category.CategoryId).where(Category.GroupId == category_group.GroupId).subquery() + subq = select(Category.CategoryId).where(Category.GroupId == category_group.GroupId) stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(subq)) else: @@ -146,8 +146,8 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]": Returns: list[str]: All users with submissions in the guild. """ - group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id).subquery() - category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids)).subquery() + group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id) + category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids)) stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids)) users_list: "list[str]" = list(session.scalars(stmt))