more efficient subscribers query, using a join #131

This commit is contained in:
rimu 2024-03-30 15:49:26 +13:00
parent 588133fda6
commit ff7f89bfce

View file

@ -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)]