Comment page speed
This commit is contained in:
parent
cbcbbc5277
commit
0e1a3992eb
4 changed files with 12 additions and 21 deletions
|
@ -168,7 +168,7 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
|||
)
|
||||
|
||||
def _get_queryset(self, target_comment):
|
||||
if target_comment != None:
|
||||
if target_comment:
|
||||
queryset = target_comment.get_descendants(include_self=True)
|
||||
queryset = (
|
||||
queryset.select_related("author__user")
|
||||
|
@ -217,11 +217,11 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
|||
|
||||
context["has_comments"] = queryset.exists()
|
||||
context["comment_lock"] = self.is_comment_locked()
|
||||
context["comment_list"] = queryset
|
||||
context["comment_list"] = list(queryset)
|
||||
|
||||
context["vote_hide_threshold"] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD
|
||||
if queryset.exists():
|
||||
context["comment_root_id"] = queryset[0].id
|
||||
context["comment_root_id"] = context["comment_list"][0].id
|
||||
else:
|
||||
context["comment_root_id"] = 0
|
||||
context["comment_parent_none"] = 1
|
||||
|
@ -234,4 +234,5 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
|||
|
||||
context["limit"] = DEFAULT_OFFSET
|
||||
context["comment_count"] = comment_count
|
||||
context["profile"] = self.request.profile
|
||||
return context
|
||||
|
|
|
@ -15,12 +15,11 @@ from django.http import (
|
|||
HttpResponseBadRequest,
|
||||
HttpResponseForbidden,
|
||||
)
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.decorators.http import require_POST
|
||||
from django.views.generic import DetailView, UpdateView
|
||||
from django.urls import reverse_lazy
|
||||
from django.template import loader
|
||||
from reversion import revisions
|
||||
from reversion.models import Version
|
||||
|
||||
|
@ -42,11 +41,6 @@ __all__ = [
|
|||
|
||||
|
||||
@login_required
|
||||
|
||||
# def get_more_reply(request, id):
|
||||
# queryset = Comment.get_pk(id)
|
||||
|
||||
|
||||
def vote_comment(request, delta):
|
||||
if abs(delta) != 1:
|
||||
return HttpResponseBadRequest(
|
||||
|
@ -164,10 +158,11 @@ def get_comments(request, limit=10):
|
|||
|
||||
new_offset = offset + min(len(queryset), limit)
|
||||
|
||||
comment_html = loader.render_to_string(
|
||||
return render(
|
||||
request,
|
||||
"comments/content-list.html",
|
||||
{
|
||||
"request": request,
|
||||
"profile": profile,
|
||||
"comment_root_id": comment_root_id,
|
||||
"comment_list": queryset,
|
||||
"vote_hide_threshold": settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD,
|
||||
|
@ -181,8 +176,6 @@ def get_comments(request, limit=10):
|
|||
},
|
||||
)
|
||||
|
||||
return HttpResponse(comment_html)
|
||||
|
||||
|
||||
def get_show_more(request):
|
||||
return get_comments(request)
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
{% set logged_in = request.user.is_authenticated %}
|
||||
{% set profile = request.profile if logged_in else None %}
|
||||
|
||||
{% for node in mptt_tree(comment_list) recursive %}
|
||||
<li id="comment-{{ node.id }}" data-revision="{{ node.revisions - 1 }}" data-max-revision="{{ node.revisions - 1 }}"
|
||||
data-revision-ajax="{{ url('comment_revision_ajax', node.id) }}" class="comment">
|
||||
<div class="comment-display{% if node.score <= vote_hide_threshold %} bad-comment{% endif %}">
|
||||
<div class="info">
|
||||
<div class="vote">
|
||||
{% if logged_in %}
|
||||
{% if profile %}
|
||||
<a href="javascript:comment_upvote({{ node.id }})"
|
||||
class="upvote-link fa fa-chevron-up fa-fw{% if node.vote_score == 1 %} voted{% endif %}"></a>
|
||||
{% else %}
|
||||
|
@ -16,7 +13,7 @@
|
|||
{% endif %}
|
||||
<br>
|
||||
<div class="comment-score">{{ node.score }}</div>
|
||||
{% if logged_in %}
|
||||
{% if profile %}
|
||||
<a href="javascript:comment_downvote({{ node.id }})"
|
||||
class="downvote-link fa fa-chevron-down fa-fw{% if node.vote_score == -1 %} voted{% endif %}"></a>
|
||||
{% else %}
|
||||
|
@ -55,7 +52,7 @@
|
|||
<a href="?comment-id={{node.id}}#comment-{{ node.id }}" title="{{ _('Link') }}" class="comment-link">
|
||||
<i class="fa fa-link fa-fw"></i>
|
||||
</a>
|
||||
{% if logged_in and not comment_lock %}
|
||||
{% if profile and not comment_lock %}
|
||||
{% set can_edit = node.author.id == profile.id and not profile.mute %}
|
||||
{% if can_edit %}
|
||||
<a data-featherlight="{{ url('comment_edit_ajax', node.id) }}"
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
{% endif %}
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
let loading_gif = "<img src=\"{{static('loading.gif')}}\" style=\"height: 1.5em; margin-bottom: 3px\" class=\"loading\">";
|
||||
let loading_gif = "<img src=\"{{static('loading.gif')}}\" style=\"height: 3em; margin-bottom: 3px\" class=\"loading\">";
|
||||
window.reply_comment = function (parent) {
|
||||
var $comment_reply = $('#comment-' + parent + '-reply');
|
||||
var reply_id = 'reply-' + parent;
|
||||
|
|
Loading…
Reference in a new issue