You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by di...@apache.org on 2022/07/14 15:22:26 UTC
[allura] branch dw/8447 updated: [#8447] thread optimize - only precache references to posts on current 'page'
This is an automated email from the ASF dual-hosted git repository.
dill0wn pushed a commit to branch dw/8447
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/dw/8447 by this push:
new dc22fb7e7 [#8447] thread optimize - only precache references to posts on current 'page'
dc22fb7e7 is described below
commit dc22fb7e7c1a17ded4ffc0b6fcb376606639591b
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Thu Jul 14 15:22:04 2022 +0000
[#8447] thread optimize - only precache references to posts on current 'page'
---
Allura/allura/lib/widgets/discuss.py | 21 +++++++++++++++------
Allura/allura/templates/widgets/thread_widget.html | 19 +++++++++----------
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index 35328780f..8a6dc86a0 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -20,12 +20,13 @@ from formencode import validators as fev
import ew as ew_core
import ew.jinja2_ew as ew
+from tg import app_globals as g
+
from allura.lib import utils
from allura.lib import validators as v
from allura.lib.widgets import form_fields as ffw
from allura.lib.widgets import forms as ff
from allura import model as M
-import six
class NullValidator(fev.FancyValidator):
@@ -337,6 +338,7 @@ class Thread(HierWidget):
page=None,
limit=50,
count=None,
+ posts=None,
show_subject=False,
new_post_text='+ New Comment')
widgets = dict(
@@ -350,7 +352,14 @@ class Thread(HierWidget):
context = super().prepare_context(context)
# bulk fetch backrefs to save on many queries within EW
thread: M.Thread = context['value']
- posts = thread.posts
+
+ page = context.get('page')
+ limit = context.get('limit')
+ limit, page, _ = g.handle_paging(limit, page)
+ posts: list[M.Post] = thread.find_posts(page=page, limit=limit)
+
+ context['posts'] = posts
+
post_ids = [post._id for post in posts]
post_index_ids = [post.index_id() for post in posts]
@@ -363,15 +372,15 @@ class Thread(HierWidget):
break
# prefill backrefs
- refs = M.ArtifactReference.query.find(dict(references={'$in': post_index_ids})).all()
+ backrefs = M.ArtifactReference.query.find(dict(references={'$in': post_index_ids})).all()
for post in posts:
- post._backrefs = [ref._id for ref in refs if post.index_id() in (ref.references or [])]
+ post._backrefs = [ref._id for ref in backrefs if post.index_id() in (ref.references or [])]
# prefill attachments
- refs = thread.attachment_class().query.find(
+ attachments = thread.attachment_class().query.find(
dict(app_config_id=thread.app_config_id, artifact_id={'$in': post_ids}, type='attachment')).all()
for post in posts:
- post._attachments = [ref for ref in refs if post._id == ref.post_id]
+ post._attachments = [att for att in attachments if post._id == att.post_id]
return context
def resources(self):
diff --git a/Allura/allura/templates/widgets/thread_widget.html b/Allura/allura/templates/widgets/thread_widget.html
index 2bd0f65f7..46df6eee2 100644
--- a/Allura/allura/templates/widgets/thread_widget.html
+++ b/Allura/allura/templates/widgets/thread_widget.html
@@ -24,16 +24,15 @@
{{widgets.page_list.display(limit=limit, page=page, count=count)}}
{% endif %}
<div id="comment">
- {% set posts = value.find_posts(page=page, limit=limit) %}
- {% if posts %}
- {% for t in value.create_post_threads(posts) %}
- <ul>
- {{widgets.post_thread.display(value=t['post'], children=t['children'],
- indent=0, show_subject=show_subject,
- page=page, limit=limit, primary_artifact=primary_artifact)}}
- </ul>
- {% endfor %}
- {% endif %}
+ {% if posts %}
+ {% for t in value.create_post_threads(posts) %}
+ <ul>
+ {{widgets.post_thread.display(value=t['post'], children=t['children'],
+ indent=0, show_subject=show_subject,
+ page=page, limit=limit, primary_artifact=primary_artifact)}}
+ </ul>
+ {% endfor %}
+ {% endif %}
{% if h.has_access(value, 'moderate')() %}
<div id="allow_moderate"></div>
{% endif %}