Commit 2f4c70e3 authored by Michal Čihař's avatar Michal Čihař

Cache commit information

So that we don't have to execute Git on every request here.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 00838956
......@@ -24,6 +24,7 @@ from django.core.mail import mail_admins
from django.core.exceptions import ValidationError
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.utils import timezone
from glob import glob
import os
......@@ -386,13 +387,28 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return self._repository
def clear_repo_cache(self):
"""
Clears cached information on repository update.
"""
cache.delete(
'{0}-last-commit'.format(self.get_full_slug())
)
def get_last_remote_commit(self):
'''
Returns latest remote commit we know.
'''
return self.repository.get_revision_info(
self.repository.last_remote_revision
)
cache_key = '{0}-last-commit'.format(self.get_full_slug())
result = cache.get(cache_key)
if result is None:
result = self.repository.get_revision_info(
self.repository.last_remote_revision
)
cache.set(cache_key, result)
return result
def get_repo_url(self):
'''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment