vcs: optimized pre-load attributes for better caching.

This commit is contained in:
Marcin Kuzminski 2019-07-17 13:50:26 +02:00
parent 16c2d9514a
commit cab16efa4e
6 changed files with 13 additions and 14 deletions

View file

@ -458,7 +458,7 @@ class BaseReferencesView(RepoAppView):
def load_refs_context(self, ref_items, partials_template):
_render = self.request.get_partial_renderer(partials_template)
pre_load = ["author", "date", "message"]
pre_load = ["author", "date", "message", "parents"]
is_svn = h.is_svn(self.rhodecode_vcs_repo)
is_hg = h.is_hg(self.rhodecode_vcs_repo)

View file

@ -211,7 +211,7 @@ class RepoCompareView(RepoAppView):
c.source_ref_type = source_ref_type
c.target_ref_type = target_ref_type
pre_load = ["author", "branch", "date", "message"]
pre_load = ["author", "date", "message", "branch"]
c.ancestor = None
try:

View file

@ -687,7 +687,7 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
commit_cache = collections.OrderedDict()
missing_requirements = False
try:
pre_load = ["author", "branch", "date", "message", "parents"]
pre_load = ["author", "date", "message", "branch", "parents"]
show_revs = pull_request_at_ver.revisions
for rev in show_revs:
comm = commits_source_repo.get_commit(

View file

@ -50,8 +50,6 @@ class GitCommit(base.BaseCommit):
_filter_pre_load = [
# done through a more complex tree walk on parents
"affected_files",
# based on repository cached property
"branch",
# done through subprocess not remote call
"children",
# done through a more complex tree walk on parents
@ -82,6 +80,7 @@ class GitCommit(base.BaseCommit):
self._submodules = None
def _set_bulk_properties(self, pre_load):
if not pre_load:
return
pre_load = [entry for entry in pre_load
@ -98,6 +97,8 @@ class GitCommit(base.BaseCommit):
value = utcdate_fromtimestamp(*value)
elif attr == "parents":
value = self._make_commits(value)
elif attr == "branch":
value = value[0] if value else None
self.__dict__[attr] = value
@LazyProperty
@ -157,12 +158,10 @@ class GitCommit(base.BaseCommit):
@LazyProperty
def branch(self):
# actually commit can have multiple branches
branches = self.commit_branches
branches = safe_unicode(self._remote.branch(self.raw_id))
if branches:
return branches[0]
return None
# actually commit can have multiple branches in git
return safe_unicode(branches[0])
def _get_tree_id_for_path(self, path):
path = safe_str(path)

View file

@ -432,7 +432,7 @@ class FileNode(Node):
@LazyProperty
def last_commit(self):
if self.commit:
pre_load = ["author", "date", "message"]
pre_load = ["author", "date", "message", "parents"]
return self.commit.get_path_commit(self.path, pre_load=pre_load)
raise NodeError(
"Cannot retrieve last commit of the file without "
@ -548,7 +548,7 @@ class FileNode(Node):
"""
if self.commit is None:
raise NodeError('Unable to get commit for this FileNode')
pre_load = ["author", "date", "message"]
pre_load = ["author", "date", "message", "parents"]
return self.commit.get_file_annotate(self.path, pre_load=pre_load)
@LazyProperty
@ -756,7 +756,7 @@ class DirNode(Node):
@LazyProperty
def last_commit(self):
if self.commit:
pre_load = ["author", "date", "message"]
pre_load = ["author", "date", "message", "parents"]
return self.commit.get_path_commit(self.path, pre_load=pre_load)
raise NodeError(
"Cannot retrieve last commit of the file without "

View file

@ -749,7 +749,7 @@ class PullRequestModel(BaseModel):
# re-compute commit ids
old_commit_ids = pull_request.revisions
pre_load = ["author", "branch", "date", "message"]
pre_load = ["author", "date", "message", "branch"]
commit_ranges = target_repo.compare(
target_commit.raw_id, source_commit.raw_id, source_repo, merge=True,
pre_load=pre_load)