Commit ef41bbc0 authored by Michal Čihař's avatar Michal Čihař

Centralize path cache handling

parent 1c745fe9
......@@ -110,18 +110,33 @@ class PathMixin(object):
'''
Mixin for path manipulations.
'''
_dir_path = None
def _get_path(self):
'''
Actual calculation of path.
'''
raise NotImplementedError()
def get_path(self):
'''
Return path to directory.
Caching is really necessary for linked project, otherwise
we end up fetching linked subproject again and again.
'''
raise NotImplementedError()
if self._dir_path is None:
self._dir_path = self._get_path()
return self._dir_path
def check_rename(self, old):
'''
Detects slug changes and possibly renames underlaying directory.
'''
if old.slug != self.slug:
os.rename(
old.get_path(),
self.get_path()
)
old_path = old.get_path()
# Invalidate cache
self._dir_path = None
new_path = self.get_path()
os.rename(old_path, new_path)
......@@ -262,7 +262,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
[subproject.locked for subproject in self.subproject_set.all()]
)
def get_path(self):
def _get_path(self):
return os.path.join(appsettings.GIT_ROOT, self.slug)
def __unicode__(self):
......
......@@ -236,7 +236,6 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self._file_format = None
self._template_store = None
self._percents = None
self._dir_path = None
def has_acl(self, user):
'''
......@@ -286,22 +285,14 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
def get_full_slug(self):
return '%s__%s' % (self.project.slug, self.slug)
def get_path(self):
def _get_path(self):
'''
Returns full path to subproject git repository.
Caching is really necessary for linked project, otherwise
we end up fetching linked subproject again and again.
'''
if self._dir_path is None:
if self.is_repo_link():
self._dir_path = self.linked_subproject.get_path()
else:
self._dir_path = os.path.join(
self.project.get_path(), self.slug
)
return self._dir_path
if self.is_repo_link():
return self.linked_subproject.get_path()
else:
return os.path.join(self.project.get_path(), self.slug)
def get_git_lock_path(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