changeset 5770:82f818616265

db: cache SCM instance short-term (tied to SQLAlchemy session lifetime) Repeatedly checking whether SCM instances are invalidated is slow, and we don't actually _want_ SCM instances to invalidate half-way through a request either. Therefore cache them in on the db.Repository object, the lifetime of which is directly tied to the lifetime of the SQLAlchemy session, the lifetime of which is tied directly to the individual HTTP request. This way, we only check for invalidation the first time the SCM instance is accessed in a request. This will improve performance in cases where we have (by definition) badly written code that retrieves repo objects several times.
author Søren Løvborg <sorenl@unity3d.com>
date Tue, 08 Mar 2016 12:28:06 +0100
parents 6afa528ee30e
children cbff502c9e54
files kallithea/model/db.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/db.py	Mon Mar 14 16:17:46 2016 +0100
+++ b/kallithea/model/db.py	Tue Mar 08 12:28:06 2016 +0100
@@ -1437,9 +1437,13 @@
         """
         CacheInvalidation.set_invalidate(self.repo_name)
 
+    _scm_instance = None
+
     @property
     def scm_instance(self):
-        return self.scm_instance_cached()
+        if self._scm_instance is None:
+            self._scm_instance = self.scm_instance_cached()
+        return self._scm_instance
 
     def scm_instance_cached(self, valid_cache_keys=None):
         @cache_region('long_term', 'scm_instance_cached')