Changeset - 82f818616265
[Not reviewed]
default
0 1 0
Søren Løvborg - 10 years ago 2016-03-08 12:28:06
sorenl@unity3d.com
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.
1 file changed with 5 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -1437,9 +1437,13 @@ class Repository(Base, BaseModel):
 
        """
 
        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')
0 comments (0 inline, 0 general)