From ff7f89bfcecb72d9a21d75cd39f96c725b3c32e0 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:49:26 +1300 Subject: [PATCH] more efficient subscribers query, using a join #131 --- app/community/routes.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/community/routes.py b/app/community/routes.py index 15e845ef..19879e68 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -955,15 +955,13 @@ def community_moderate_subscribers(actor): if community is not None: if community.is_moderator() or current_user.is_admin(): - #TODO - not sure if this is the most efficient query and we might want to look in to paging the results - subscribers = CommunityMember.query.filter(CommunityMember.community_id == community.id).all() - subscriber_user_ids = [subscriber.user_id for subscriber in subscribers] - subscriber_list = User.query.filter(User.id.in_(subscriber_user_ids)).all() + subscribers = User.query.join(CommunityMember, CommunityMember.user_id == User.id).filter(CommunityMember.community_id == community.id) + subscribers = subscribers.filter(CommunityMember.is_banned == False).all() banned_people = User.query.join(CommunityBan, CommunityBan.user_id == User.id).filter(CommunityBan.community_id == community.id).all() return render_template('community/community_moderate_subscribers.html', title=_('Moderation of %(community)s', community=community.display_name()), - community=community, current='subscribers', subscribers=subscriber_list, banned_people=banned_people, + community=community, current='subscribers', subscribers=subscribers, banned_people=banned_people, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), inoculation=inoculation[randint(0, len(inoculation) - 1)]