Improve user comments page performance

This commit is contained in:
rubenwardy 2023-09-29 23:10:08 +01:00
parent 315337d552
commit 43af3a8e75
2 changed files with 10 additions and 6 deletions

@ -397,13 +397,11 @@ def user_comments(username):
# Filter replies the current user can see # Filter replies the current user can see
query = ThreadReply.query.options(selectinload(ThreadReply.thread)).filter_by(author=user) query = ThreadReply.query.options(selectinload(ThreadReply.thread)).filter_by(author=user)
only_public = False
if current_user != user and not (current_user.is_authenticated and current_user.rank.at_least(UserRank.APPROVER)): if current_user != user and not (current_user.is_authenticated and current_user.rank.at_least(UserRank.APPROVER)):
if user.username == "ContentDB" or not current_user.is_authenticated: query = query.filter(ThreadReply.thread.has(private=False))
# The ContentDB user simply has too many comments, don't bother checking more than thread privacy only_public = True
query = query.filter(ThreadReply.thread.has(private=False))
else:
query = query.filter(or_(ThreadReply.thread.has(private=False), Thread.watchers.contains(current_user)))
pagination = query.order_by(db.desc(ThreadReply.created_at)).paginate(page=page, per_page=num) pagination = query.order_by(db.desc(ThreadReply.created_at)).paginate(page=page, per_page=num)
return render_template("threads/user_comments.html", user=user, pagination=pagination) return render_template("threads/user_comments.html", user=user, pagination=pagination, only_public=only_public)

@ -67,6 +67,12 @@
</ul> </ul>
{{ render_pagination(pagination, url_set_query) }} {{ render_pagination(pagination, url_set_query) }}
{% if only_public %}
<p class="mt-5 text-muted">
{{ _("Only showing replies to public threads") }}
</p>
{% endif %}
{% else %} {% else %}
<p> <p>
<i> <i>