mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
optimize can vote checking
This commit is contained in:
parent
cb7d4fc40f
commit
e6d81db15f
4 changed files with 17 additions and 9 deletions
|
@ -225,7 +225,9 @@ def show_community(community: Community):
|
||||||
if current_user.is_anonymous:
|
if current_user.is_anonymous:
|
||||||
posts = posts.filter(Post.from_bot == False, Post.nsfw == False, Post.nsfl == False, Post.deleted == False)
|
posts = posts.filter(Post.from_bot == False, Post.nsfw == False, Post.nsfl == False, Post.deleted == False)
|
||||||
content_filters = {}
|
content_filters = {}
|
||||||
|
user = None
|
||||||
else:
|
else:
|
||||||
|
user = current_user
|
||||||
if current_user.ignore_bots == 1:
|
if current_user.ignore_bots == 1:
|
||||||
posts = posts.filter(Post.from_bot == False)
|
posts = posts.filter(Post.from_bot == False)
|
||||||
if current_user.hide_nsfl == 1:
|
if current_user.hide_nsfl == 1:
|
||||||
|
@ -330,7 +332,7 @@ def show_community(community: Community):
|
||||||
etag=f"{community.id}{sort}{post_layout}_{hash(community.last_active)}", related_communities=related_communities,
|
etag=f"{community.id}{sort}{post_layout}_{hash(community.last_active)}", related_communities=related_communities,
|
||||||
next_url=next_url, prev_url=prev_url, low_bandwidth=low_bandwidth, un_moderated=un_moderated,
|
next_url=next_url, prev_url=prev_url, low_bandwidth=low_bandwidth, un_moderated=un_moderated,
|
||||||
recently_upvoted=recently_upvoted, recently_downvoted=recently_downvoted,
|
recently_upvoted=recently_upvoted, recently_downvoted=recently_downvoted,
|
||||||
canonical=community.profile_id(),
|
canonical=community.profile_id(), can_upvote_here=can_upvote(user, community), can_downvote_here=can_downvote(user, community, g.site),
|
||||||
rss_feed=f"https://{current_app.config['SERVER_NAME']}/community/{community.link()}/feed", rss_feed_name=f"{community.title} on {g.site.name}",
|
rss_feed=f"https://{current_app.config['SERVER_NAME']}/community/{community.link()}/feed", rss_feed_name=f"{community.title} on {g.site.name}",
|
||||||
content_filters=content_filters, moderating_communities=moderating_communities(current_user.get_id()),
|
content_filters=content_filters, moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id()),
|
joined_communities=joined_communities(current_user.get_id()),
|
||||||
|
|
|
@ -32,7 +32,7 @@ from app.utils import get_setting, render_template, allowlist_html, markdown_to_
|
||||||
blocked_instances, blocked_domains, community_moderators, blocked_phrases, show_ban_message, recently_upvoted_posts, \
|
blocked_instances, blocked_domains, community_moderators, blocked_phrases, show_ban_message, recently_upvoted_posts, \
|
||||||
recently_downvoted_posts, recently_upvoted_post_replies, recently_downvoted_post_replies, reply_is_stupid, \
|
recently_downvoted_posts, recently_upvoted_post_replies, recently_downvoted_post_replies, reply_is_stupid, \
|
||||||
languages_for_form, menu_topics, add_to_modlog, blocked_communities, piefed_markdown_to_lemmy_markdown, \
|
languages_for_form, menu_topics, add_to_modlog, blocked_communities, piefed_markdown_to_lemmy_markdown, \
|
||||||
permission_required, blocked_users, get_request, is_local_image_url, is_video_url
|
permission_required, blocked_users, get_request, is_local_image_url, is_video_url, can_upvote, can_downvote
|
||||||
from app.shared.reply import make_reply, edit_reply
|
from app.shared.reply import make_reply, edit_reply
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,9 +161,13 @@ def show_post(post_id: int):
|
||||||
|
|
||||||
# for logged in users who have the 'hide read posts' function enabled
|
# for logged in users who have the 'hide read posts' function enabled
|
||||||
# mark this post as read
|
# mark this post as read
|
||||||
if current_user.is_authenticated and current_user.hide_read_posts:
|
if current_user.is_authenticated:
|
||||||
|
user = current_user
|
||||||
|
if current_user.hide_read_posts:
|
||||||
current_user.mark_post_as_read(post)
|
current_user.mark_post_as_read(post)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
else:
|
||||||
|
user = None
|
||||||
|
|
||||||
response = render_template('post/post.html', title=post.title, post=post, is_moderator=is_moderator, is_owner=community.is_owner(),
|
response = render_template('post/post.html', title=post.title, post=post, is_moderator=is_moderator, is_owner=community.is_owner(),
|
||||||
community=post.community,
|
community=post.community,
|
||||||
|
@ -177,6 +181,8 @@ def show_post(post_id: int):
|
||||||
recently_upvoted_replies=recently_upvoted_replies, recently_downvoted_replies=recently_downvoted_replies,
|
recently_upvoted_replies=recently_upvoted_replies, recently_downvoted_replies=recently_downvoted_replies,
|
||||||
reply_collapse_threshold=reply_collapse_threshold,
|
reply_collapse_threshold=reply_collapse_threshold,
|
||||||
etag=f"{post.id}{sort}_{hash(post.last_active)}", markdown_editor=current_user.is_authenticated and current_user.markdown_editor,
|
etag=f"{post.id}{sort}_{hash(post.last_active)}", markdown_editor=current_user.is_authenticated and current_user.markdown_editor,
|
||||||
|
can_upvote_here=can_upvote(user, community),
|
||||||
|
can_downvote_here=can_downvote(user, community, g.site),
|
||||||
low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1',
|
low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1',
|
||||||
moderating_communities=moderating_communities(current_user.get_id()),
|
moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id()),
|
joined_communities=joined_communities(current_user.get_id()),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% if current_user.is_authenticated and current_user.verified %}
|
{% if current_user.is_authenticated and current_user.verified %}
|
||||||
{% if disable_voting %} {% endif %}
|
{% if disable_voting %} {% endif %}
|
||||||
{% if can_upvote(current_user, community) and not disable_voting %}
|
{% if (can_upvote_here or can_upvote(current_user, community)) and not disable_voting %}
|
||||||
<div class="upvote_button {{ 'voted_up' if in_sorted_list(recently_upvoted_replies, comment.id) }}" role="button" aria-label="{{ _('UpVote button.') }}" aria-live="assertive"
|
<div class="upvote_button {{ 'voted_up' if in_sorted_list(recently_upvoted_replies, comment.id) }}" role="button" aria-label="{{ _('UpVote button.') }}" aria-live="assertive"
|
||||||
hx-post="/comment/{{ comment.id }}/upvote" hx-trigger="click throttle:1s" hx-target="closest .voting_buttons_new" tabindex="0">
|
hx-post="/comment/{{ comment.id }}/upvote" hx-trigger="click throttle:1s" hx-target="closest .voting_buttons_new" tabindex="0">
|
||||||
<span class="fe fe-arrow-up"></span>
|
<span class="fe fe-arrow-up"></span>
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span title="{{ comment.up_votes }}, {{ comment.down_votes }}" aria-live="assertive" aria-label="{{ _('Score: ') }}{{ comment.up_votes - comment.down_votes }}.">{{ comment.up_votes - comment.down_votes }}</span>
|
<span title="{{ comment.up_votes }}, {{ comment.down_votes }}" aria-live="assertive" aria-label="{{ _('Score: ') }}{{ comment.up_votes - comment.down_votes }}.">{{ comment.up_votes - comment.down_votes }}</span>
|
||||||
{% if can_downvote(current_user, community) and not disable_voting %}
|
{% if (can_downvote_here or can_downvote(current_user, community)) and not disable_voting %}
|
||||||
<div class="downvote_button {{ 'voted_down' if in_sorted_list(recently_downvoted_replies, comment.id) }}" role="button" aria-label="{{ _('DownVote button.') }}" aria-live="assertive"
|
<div class="downvote_button {{ 'voted_down' if in_sorted_list(recently_downvoted_replies, comment.id) }}" role="button" aria-label="{{ _('DownVote button.') }}" aria-live="assertive"
|
||||||
hx-post="/comment/{{ comment.id }}/downvote" hx-trigger="click throttle:1s" hx-target="closest .voting_buttons_new" tabindex="0">
|
hx-post="/comment/{{ comment.id }}/downvote" hx-trigger="click throttle:1s" hx-target="closest .voting_buttons_new" tabindex="0">
|
||||||
<span class="fe fe-arrow-down"></span>
|
<span class="fe fe-arrow-down"></span>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% if current_user.is_authenticated and current_user.verified -%}
|
{% if current_user.is_authenticated and current_user.verified -%}
|
||||||
{% if can_upvote(current_user, post.community) and not disable_voting -%}
|
{% if (can_upvote_here or can_upvote(current_user, post.community)) and not disable_voting -%}
|
||||||
<div class="upvote_button {{ 'voted_up' if in_sorted_list(recently_upvoted, post.id) }}" role="button" aria-label="{{ _('UpVote button, %(count)d upvotes so far.', count=post.up_votes) }}" aria-live="assertive"
|
<div class="upvote_button {{ 'voted_up' if in_sorted_list(recently_upvoted, post.id) }}" role="button" aria-label="{{ _('UpVote button, %(count)d upvotes so far.', count=post.up_votes) }}" aria-live="assertive"
|
||||||
hx-post="/post/{{ post.id }}/upvote" hx-trigger="click throttle:1s" hx-target="closest .voting_buttons_new" tabindex="0">
|
hx-post="/post/{{ post.id }}/upvote" hx-trigger="click throttle:1s" hx-target="closest .voting_buttons_new" tabindex="0">
|
||||||
<span class="fe fe-arrow-up"></span>
|
<span class="fe fe-arrow-up"></span>
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
<span title="{{ post.up_votes }}, {{ post.down_votes }}" aria-live="assertive" aria-label="{{ _('Score: ') }}{{ post.up_votes - post.down_votes }}.">{{ shorten_number(post.up_votes - post.down_votes) }}</span>
|
<span title="{{ post.up_votes }}, {{ post.down_votes }}" aria-live="assertive" aria-label="{{ _('Score: ') }}{{ post.up_votes - post.down_votes }}.">{{ shorten_number(post.up_votes - post.down_votes) }}</span>
|
||||||
{%- if can_downvote(current_user, post.community) and not disable_voting -%}
|
{%- if (can_downvote_here or can_downvote(current_user, post.community)) and not disable_voting -%}
|
||||||
<div class="downvote_button {{ 'voted_down' if in_sorted_list(recently_downvoted, post.id) }}" role="button" aria-label="{{ _('DownVote button, %(count)d downvotes so far.', count=post.down_votes) }}" aria-live="assertive"
|
<div class="downvote_button {{ 'voted_down' if in_sorted_list(recently_downvoted, post.id) }}" role="button" aria-label="{{ _('DownVote button, %(count)d downvotes so far.', count=post.down_votes) }}" aria-live="assertive"
|
||||||
hx-post="/post/{{ post.id }}/downvote" hx-trigger="click throttle:1s" hx-target="closest .voting_buttons_new" tabindex="0">
|
hx-post="/post/{{ post.id }}/downvote" hx-trigger="click throttle:1s" hx-target="closest .voting_buttons_new" tabindex="0">
|
||||||
<span class="fe fe-arrow-down"></span>
|
<span class="fe fe-arrow-down"></span>
|
||||||
|
|
Loading…
Add table
Reference in a new issue