You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2022/03/30 18:12:05 UTC

[allura] 02/02: [#4359] move ArtifactReference bulk fetch into shared Thread widget

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 53faa1038eda2d6be04453d200ffdd0d97668e80
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Wed Mar 30 12:49:14 2022 -0400

    [#4359] move ArtifactReference bulk fetch into shared Thread widget
---
 Allura/allura/controllers/discuss.py |  6 ------
 Allura/allura/lib/widgets/discuss.py | 10 ++++++++++
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index 07afb1e..ddaf61b 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -208,12 +208,6 @@ class ThreadController(BaseController, FeedController, metaclass=h.ProxiedAttrMe
         M.session.artifact_orm_session._get().skip_last_updated = True
         count = self.thread.query_posts(page=page, limit=int(limit)).count()
 
-        # bulk fetch backrefs to save on many queries within EW
-        index_ids = [a.index_id() for a in self.thread.discussion.posts]
-        q = ArtifactReference.query.find(dict(references={'$in': index_ids})).all()
-        for a in self.thread.discussion.posts:
-            a._backrefs = [aref._id for aref in q if a.index_id() in (aref.references or [])]
-
         return dict(discussion=self.thread.discussion,
                     thread=self.thread,
                     page=int(page),
diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index 3bbdd88..101f83a 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -346,6 +346,16 @@ class Thread(HierWidget):
         post=Post(),
         edit_post=EditPost(submit_text='Submit'))
 
+    def prepare_context(self, context):
+        context = super().prepare_context(context)
+        # bulk fetch backrefs to save on many queries within EW
+        thread: M.Thread = context['value']
+        index_ids = [a.index_id() for a in thread.discussion.posts]
+        q = M.ArtifactReference.query.find(dict(references={'$in': index_ids})).all()
+        for a in thread.discussion.posts:
+            a._backrefs = [aref._id for aref in q if a.index_id() in (aref.references or [])]
+        return context
+
     def resources(self):
         yield from super().resources()
         for w in self.widgets.values():