Skip to content

Cache tags -> commits for performance #6651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,28 @@ def clone(self):
def tags(self):
versions = []
repo = git.Repo(self.working_dir)

# Build a cache of tag -> commit
# GitPython is not very optimized for reading large numbers of tags
ref_cache = {} # 'ref/tags/<tag>' -> hexsha
for hexsha, ref in git.TagReference._iter_packed_refs(repo):
ref_cache[ref] = hexsha

for tag in repo.tags:
try:
versions.append(VCSVersion(self, str(tag.commit), str(tag)))
except ValueError:
# ValueError: Cannot resolve commit as tag TAGNAME points to a
# blob object - use the `.object` property instead to access it
# This is not a real tag for us, so we skip it
# https://github.com/rtfd/readthedocs.org/issues/4440
log.warning('Git tag skipped: %s', tag, exc_info=True)
continue
if tag.path in ref_cache:
hexsha = ref_cache[tag.path]
else:
try:
hexsha = str(tag.commit)
except ValueError:
# ValueError: Cannot resolve commit as tag TAGNAME points to a
# blob object - use the `.object` property instead to access it
# This is not a real tag for us, so we skip it
# https://github.com/rtfd/readthedocs.org/issues/4440
log.warning('Git tag skipped: %s', tag, exc_info=True)
continue

versions.append(VCSVersion(self, hexsha, str(tag)))
return versions

@property
Expand Down