allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [allura] 01/01: [#8313] option to configure or disable expiration of ticket search bins
Date Wed, 03 Jul 2019 14:20:10 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit ffd7c796666cd06d76c0953e79a33e262879c87c
Author: Dave Brondsema <dave@brondsema.net>
AuthorDate: Tue Jul 2 17:49:32 2019 -0400

    [#8313] option to configure or disable expiration of ticket search bins
---
 Allura/development.ini                                   |  9 +++++++--
 ForgeTracker/forgetracker/model/ticket.py                | 10 ++++++----
 .../forgetracker/tests/unit/test_globals_model.py        | 16 ++++++++++++++++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/Allura/development.ini b/Allura/development.ini
index a649f9c..4478d73 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -625,8 +625,13 @@ short_url.url_pattern = {base_url}/{nbhd}/{project}/{mount_point}/{short_name}
 ;
 userstats.count_lines_of_code = true
 
-; to avoid race condition, this needs to be a bit longer than the SOLR commitWithin delay.
-; forgetracker.bin_invalidate_delay = 5
+;
+; Settings for Ticket tracker tool
+;
+; to avoid race condition, this needs to be a bit longer than the SOLR commitWithin delay.
 Values are in minutes
+;forgetracker.bin_invalidate_delay = 5
+; Minutes to cache saved search "bins" numbers.  0 will disable entirely, so caches are permanent
+;forgetracker.bin_cache_expire = 60
 
 
 ;
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index fc30b87..9a15d05 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -199,14 +199,16 @@ class Globals(MappedClass):
             r = search_artifact(Ticket, b.terms, rows=0, short_timeout=False, fq=['-deleted_b:true'])
             hits = r is not None and r.hits or 0
             self._bin_counts_data.append(dict(summary=b.summary, hits=hits))
-        self._bin_counts_expire = \
-            datetime.utcnow() + timedelta(minutes=60)
+        cache_expire_config = int(tg_config.get('forgetracker.bin_cache_expire', 60))
+        if cache_expire_config:
+            self._bin_counts_expire = datetime.utcnow() + timedelta(minutes=cache_expire_config)
         self._bin_counts_invalidated = None
 
     def bin_count(self, name):
-        # not sure why we expire bin counts after an hour even if unchanged
+        # not sure why we expire bin counts even if unchanged
         # I guess a catch-all in case invalidate_bin_counts is missed
-        if self._bin_counts_expire < datetime.utcnow():
+        cache_expire_config = int(tg_config.get('forgetracker.bin_cache_expire', 60))
+        if cache_expire_config and (not self._bin_counts_expire or self._bin_counts_expire
< datetime.utcnow()):
             self.invalidate_bin_counts()
         for d in self._bin_counts_data:
             if d['summary'] == name:
diff --git a/ForgeTracker/forgetracker/tests/unit/test_globals_model.py b/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
index 47b36ba..d1daad3 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
@@ -62,17 +62,33 @@ class TestGlobalsModel(TrackerTestWithModel):
         gbl.invalidate_bin_counts = mock.Mock()
 
         # not expired, finds bin
+        gbl.invalidate_bin_counts.reset_mock()
         gbl._bin_counts_expire = now + timedelta(minutes=5)
         bin = gbl.bin_count('bar')
         assert_equal(bin['hits'], 2)
         assert not gbl.invalidate_bin_counts.called
 
         # expired, returns value for missing bin
+        gbl.invalidate_bin_counts.reset_mock()
         gbl._bin_counts_expire = now - timedelta(minutes=5)
         bin = gbl.bin_count('qux')
         assert_equal(bin['hits'], 0)
         assert gbl.invalidate_bin_counts.called
 
+        # config set to no expiration
+        gbl.invalidate_bin_counts.reset_mock()
+        with mock.patch.dict('forgetracker.model.ticket.tg_config', **{'forgetracker.bin_cache_expire':
0}):
+            gbl._bin_counts_expire = now - timedelta(minutes=5)
+            bin = gbl.bin_count('qux')
+            assert not gbl.invalidate_bin_counts.called
+
+        # no expire value (e.g. from previously having config set to no expirations)
+        gbl.invalidate_bin_counts.reset_mock()
+        gbl._bin_counts_expire = None
+        bin = gbl.bin_count('qux')
+        assert_equal(bin['hits'], 0)
+        assert gbl.invalidate_bin_counts.called
+
     @mock.patch('forgetracker.tasks.update_bin_counts')
     @mock.patch('forgetracker.model.ticket.datetime')
     def test_invalidate_bin_counts(self, mock_dt, mock_task):


Mime
View raw message