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 2017/05/17 21:15:27 UTC

allura git commit: [#8154] use filter query instead of main query to exclude deleted tickets

Repository: allura
Updated Branches:
  refs/heads/db/8154 [created] 86500eea4


[#8154] use filter query instead of main query to exclude deleted tickets


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/86500eea
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/86500eea
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/86500eea

Branch: refs/heads/db/8154
Commit: 86500eea48664c14c6a26c61c2880b043c7c7538
Parents: 6f15b47
Author: Dave Brondsema <da...@brondsema.net>
Authored: Wed May 17 16:52:09 2017 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Wed May 17 17:13:56 2017 -0400

----------------------------------------------------------------------
 Allura/allura/lib/search.py                        |  3 ++-
 ForgeTracker/forgetracker/model/ticket.py          | 17 ++++-------------
 ForgeTracker/forgetracker/search.py                |  4 ++--
 .../forgetracker/tests/functional/test_root.py     |  5 ++---
 4 files changed, 10 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/86500eea/Allura/allura/lib/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index 02afa05..1cf26c2 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -161,7 +161,8 @@ def search_artifact(atype, q, history=False, rows=10, short_timeout=False, filte
     fq = [
         'type_s:%s' % fields['type_s'],
         'project_id_s:%s' % c.project._id,
-        'mount_point_s:%s' % c.app.config.options.mount_point ]
+        'mount_point_s:%s' % c.app.config.options.mount_point]
+    fq += kw.pop('fq', [])
     for name, values in (filter or {}).iteritems():
         field_name = name + '_s'
         parts = []

http://git-wip-us.apache.org/repos/asf/allura/blob/86500eea/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 44da697..a22776d 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -1216,11 +1216,10 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                 # also query for choices for filter options right away
                 params = kw.copy()
                 params.update(tsearch.FACET_PARAMS)
-                q_ = q
                 if not show_deleted:
-                    q_ = cls.not_deleted_query(q_)
+                    params['fq'] = ['deleted_b:False']
                 matches = search_artifact(
-                    cls, q_, short_timeout=True,
+                    cls, q, short_timeout=True,
                     rows=limit, sort=refined_sort, start=start, fl='ticket_num_i',
                     filter=filter, **params)
             else:
@@ -1258,13 +1257,6 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                     solr_error=solr_error, **kw)
 
     @classmethod
-    def not_deleted_query(cls, search_query):
-        """Update query to exclude deleted tickets
-        search_query - query in solr syntax
-        """
-        return search_query + ' && deleted:False'
-
-    @classmethod
     def paged_query_or_search(cls, app_config, user, query, search_query, filter,
                               limit=None, page=0, sort=None, **kw):
         """Switch between paged_query and paged_search based on filter.
@@ -1282,10 +1274,9 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
             result = cls.paged_query(app_config, user, query, sort=sort, limit=limit, page=page, **kw)
             t = cls.query.find().first()
             if t:
-                if not kw.get('show_deleted',False):
-                    search_query = cls.not_deleted_query(search_query)
                 search_query = cls.translate_query(search_query, t.index())
-            result['filter_choices'] = tsearch.query_filter_choices(search_query)
+            result['filter_choices'] = tsearch.query_filter_choices(
+                search_query, fq=[] if kw.get('show_deleted', False) else ['deleted_b:False'])
         else:
             result = cls.paged_search(app_config, user, search_query, filter=filter,
                                       sort=solr_sort, limit=limit, page=page, **kw)

http://git-wip-us.apache.org/repos/asf/allura/blob/86500eea/ForgeTracker/forgetracker/search.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/search.py b/ForgeTracker/forgetracker/search.py
index 78181b8..0225997 100644
--- a/ForgeTracker/forgetracker/search.py
+++ b/ForgeTracker/forgetracker/search.py
@@ -28,7 +28,7 @@ FACET_PARAMS = {
 }
 
 
-def query_filter_choices(arg=None):
+def query_filter_choices(arg=None, fq=[]):
     """
     Makes solr query and returns facets for tickets.
 
@@ -40,7 +40,7 @@ def query_filter_choices(arg=None):
             'project_id_s:%s' % c.project._id,
             'mount_point_s:%s' % c.app.config.options.mount_point,
             'type_s:Ticket',
-            ],
+            ] + fq,
         'rows': 0,
     }
     params.update(FACET_PARAMS)

http://git-wip-us.apache.org/repos/asf/allura/blob/86500eea/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index c3d0ac4..57d840c 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -2398,15 +2398,14 @@ class TestFunctionalController(TrackerTestController):
                       ' test &lt;h2&gt; ticket</strong></p>',
                       body)
 
-    @patch('forgetracker.search.query_filter_choices')
+    @patch('forgetracker.search.query_filter_choices', autospec=True)
     def test_multiselect(self, query_filter_choices):
         self.new_ticket(summary='test')
         self.new_ticket(summary='test2')
         query_filter_choices.return_value = {'status': [('open', 2)], }
         r = self.app.get('/bugs/')
         assert '<option value="open">open (2)</option>' in r
-        assert query_filter_choices.call_count == 1
-        assert query_filter_choices.call_args[0][0] == '!status_s:wont-fix && !status_s:closed && deleted_b:False'
+        query_filter_choices.assert_called_once_with('!status_s:wont-fix && !status_s:closed', fq=['deleted_b:False'])
 
     def test_rate_limit_new(self):
         self.new_ticket(summary='First ticket')