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/01/09 21:30:49 UTC

allura git commit: Removes neighborhood cache

Repository: allura
Updated Branches:
  refs/heads/master c780b9717 -> 13534d447


Removes neighborhood cache


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

Branch: refs/heads/master
Commit: 13534d4474d1f0574a5b085dd0131834e936c3b9
Parents: c780b97
Author: Kenton Taylor <kt...@slashdotmedia.com>
Authored: Mon Jan 9 16:30:45 2017 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Jan 9 21:30:32 2017 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py |  7 +--
 Allura/allura/controllers/root.py    |  6 ++-
 Allura/allura/lib/app_globals.py     | 34 --------------
 Allura/allura/tests/test_globals.py  | 73 +------------------------------
 Allura/development.ini               |  4 --
 5 files changed, 7 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/13534d44/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 685519c..8821f9e 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -600,12 +600,7 @@ class NeighborhoodAdminController(object):
     @require_post()
     @validate(W.neighborhood_overview_form, error_handler=overview)
     def update(self, name=None, css=None, homepage=None, project_template=None, icon=None, **kw):
-        # We need to get neighborhood from Mongo to populate Ming's session. If
-        # neighborhood object is coming from cache (i.e.
-        # neighborhood.cache.duration is set), then it will be absent in Ming's
-        # session for current thread, thus all changes will not be flushed to
-        # disk. See #7890 for details.
-        nbhd = M.Neighborhood.query.get(_id=self.neighborhood._id)
+        nbhd = self.neighborhood
         c.project = nbhd.neighborhood_project
         h.log_if_changed(nbhd, 'name', name,
                          'change neighborhood name to %s' % name)

http://git-wip-us.apache.org/repos/asf/allura/blob/13534d44/Allura/allura/controllers/root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/root.py b/Allura/allura/controllers/root.py
index a0418d0..891cbc2 100644
--- a/Allura/allura/controllers/root.py
+++ b/Allura/allura/controllers/root.py
@@ -76,7 +76,7 @@ class RootController(WsgiDispatchController):
 
     def __init__(self):
         n_url_prefix = '/%s/' % request.path.split('/')[1]
-        n = g.neighborhood_cache.get(n_url_prefix)
+        n = self._lookup_neighborhood(n_url_prefix)
         if n and not n.url_prefix.startswith('//'):
             n.bind_controller(self)
         self.browse = ProjectBrowseController()
@@ -84,6 +84,10 @@ class RootController(WsgiDispatchController):
 
         super(RootController, self).__init__()
 
+    def _lookup_neighborhood(self, url_prefix):
+        n = M.Neighborhood.query.get(url_prefix=url_prefix)
+        return n
+
     def _setup_request(self):
         c.project = c.app = None
         c.user = plugin.AuthenticationProvider.get(request).authenticate_request()

http://git-wip-us.apache.org/repos/asf/allura/blob/13534d44/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 1921412..749edda 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -139,36 +139,6 @@ class ForgeMarkdown(markdown.Markdown):
         return html
 
 
-class NeighborhoodCache(object):
-    """Cached Neighborhood objects by url_prefix.
-    For faster RootController.__init__ lookup
-    """
-
-    def __init__(self, duration):
-        self.duration = duration
-        self._data = {}
-
-    def _lookup(self, url_prefix):
-        n = M.Neighborhood.query.get(url_prefix=url_prefix)
-        self._data[url_prefix] = {
-            'object': n,
-            'ts': datetime.datetime.utcnow(),
-        }
-        return n
-
-    def _expired(self, n):
-        delta = datetime.datetime.utcnow() - n['ts']
-        if delta >= datetime.timedelta(seconds=self.duration):
-            return True
-        return False
-
-    def get(self, url_prefix):
-        n = self._data.get(url_prefix)
-        if n and not self._expired(n):
-            return n['object']
-        return self._lookup(url_prefix)
-
-
 class Globals(object):
 
     """Container for objects available throughout the life of the application.
@@ -311,10 +281,6 @@ class Globals(object):
             multifactor_recovery_code=_cache_eps('allura.multifactor.recovery_code'),
         )
 
-        # Neighborhood cache
-        duration = asint(config.get('neighborhood.cache.duration', 0))
-        self.neighborhood_cache = NeighborhoodCache(duration)
-
         # Set listeners to update stats
         statslisteners = []
         for name, ep in self.entry_points['stats'].iteritems():

http://git-wip-us.apache.org/repos/asf/allura/blob/13534d44/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 3c83a78..9b53d05 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -42,7 +42,7 @@ from alluratest.controller import (
 
 from allura import model as M
 from allura.lib import helpers as h
-from allura.lib.app_globals import ForgeMarkdown, NeighborhoodCache
+from allura.lib.app_globals import ForgeMarkdown
 from allura.tests import decorators as td
 
 from forgewiki import model as WM
@@ -804,77 +804,6 @@ class TestHandlePaging(unittest.TestCase):
         self.assertEqual(c.user.get_pref('results_per_page'), 25)
 
 
-class TestNeighborhoodCache(object):
-
-    @patch('allura.lib.app_globals.M', autospec=True)
-    @patch('allura.lib.app_globals.datetime', autospec=True)
-    def test_lookup(self, dt_mock, M):
-        dt_mock.datetime.utcnow.side_effect = [
-            dt.datetime(2015, 02, 05, 11, 32),
-            dt.datetime(2015, 02, 05, 11, 34),
-        ]
-        ret = M.Neighborhood.query.get.return_value
-        cache = NeighborhoodCache(30)
-        assert_equal(cache._data, {})
-
-        n = cache._lookup('/p/')
-        M.Neighborhood.query.get.assert_called_once_with(url_prefix='/p/')
-        assert_equal(n, ret)
-        assert_equal(cache._data, {'/p/': {
-            'object': ret,
-            'ts': dt.datetime(2015, 02, 05, 11, 32),
-        }})
-
-        # hits mongo every time
-        n = cache._lookup('/p/')
-        assert_equal(M.Neighborhood.query.get.call_count, 2)
-        assert_equal(n, ret)
-        assert_equal(cache._data, {'/p/': {
-            'object': ret,
-            'ts': dt.datetime(2015, 02, 05, 11, 34),
-        }})
-
-    @patch('allura.lib.app_globals.M', autospec=True)
-    @patch('allura.lib.app_globals.datetime', autospec=True)
-    def test_get(self, dt_mock, M):
-        dt_mock.datetime.utcnow.side_effect = [
-            dt.datetime(2015, 02, 05, 11, 32),
-            dt.datetime(2015, 02, 05, 11, 34),
-        ]
-        ret = M.Neighborhood.query.get.return_value
-        cache = NeighborhoodCache(30)
-        cache._expired = Mock(return_value=False)
-
-        n = cache.get('/p/')
-        M.Neighborhood.query.get.assert_called_once_with(url_prefix='/p/')
-        assert_equal(n, ret)
-
-        # don't hit mongo second time
-        n = cache.get('/p/')
-        assert_equal(M.Neighborhood.query.get.call_count, 1)
-        assert_equal(n, ret)
-
-        # and hits if cache is expired
-        cache._expired.return_value = True
-        n = cache.get('/p/')
-        assert_equal(M.Neighborhood.query.get.call_count, 2)
-        assert_equal(n, ret)
-
-    @patch('allura.lib.app_globals.datetime', autospec=True)
-    def test_expired(self, dt_mock):
-        dt_mock.timedelta = dt.timedelta  # restore original
-        _now = dt.datetime(2015, 02, 05, 11, 53)
-        dt_mock.datetime.utcnow.return_value = _now
-
-        cache = NeighborhoodCache(0)
-        assert_equal(cache._expired({'ts': _now}), True)
-        assert_equal(cache._expired({'ts': _now - dt.timedelta(seconds=1)}), True)
-
-        cache = NeighborhoodCache(30)
-        assert_equal(cache._expired({'ts': _now - dt.timedelta(seconds=29)}), False)
-        assert_equal(cache._expired({'ts': _now - dt.timedelta(seconds=30)}), True)
-
-
 class TestIconRender(object):
 
     def setUp(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/13534d44/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 8acd25d..b98b170 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -101,10 +101,6 @@ build_key=1276635823
 ; Used by Turbogears / Pylons in some cases.  Not particularly relevant for Allura.
 cache_dir = %(here)s/data
 
-; Cache Neighborhood objects for N seconds (speeds up requests).
-; Set to 0 to disable (the default).
-;neighborhood.cache.duration = 0
-
 ; Template cache settings
 ; See http://jinja.pocoo.org/docs/api/#jinja2.Environment
 jinja_cache_size = -1