Browse Source

Speed up loading change screen

If a change has many revisions, loading the change screen may be
slow because we verify the presence of each commit and its parent
individually.

Instead, do that in a batch to speed things up.

Change-Id: Ib4b1c34500b98b8bb7307a5aaca86802a15e635d
changes/00/497600/1
James E. Blair 4 years ago
parent
commit
cb12ada037
  1. 18
      gertty/gitrepo.py
  2. 3
      gertty/sync.py
  3. 19
      gertty/view/change.py

18
gertty/gitrepo.py

@ -259,15 +259,17 @@ class Repo(object):
raise GitCloneError("No URL available for git clone")
git.Repo.clone_from(self.url, self.path)
def hasCommit(self, sha):
def checkCommits(self, shas):
invalid = set()
repo = git.Repo(self.path)
try:
repo.commit(sha)
except gitdb.exc.BadObject:
return False
except ValueError:
return False
return True
for sha in shas:
try:
repo.commit(sha)
except gitdb.exc.BadObject:
invalid.add(sha)
except ValueError:
invalid.add(sha)
return invalid
def fetch(self, url, refspec):
repo = git.Repo(self.path)

3
gertty/sync.py

@ -989,8 +989,7 @@ class CheckRevisionsTask(Task):
for change in project.open_changes:
if repo:
for revision in change.revisions:
if not (repo.hasCommit(revision.parent) and
repo.hasCommit(revision.commit)):
if repo.checkCommits([revision.parent, revision.commit]):
to_sync.add(change.id)
else:
to_sync.add(change.id)

19
gertty/view/change.py

@ -415,16 +415,16 @@ class ChangeMessageBox(mywid.HyperText):
if message.author.username == self.app.config.username:
name_style = 'change-message-own-name'
header_style = 'change-message-own-header'
reviewer_string = message.author.name
reviewer_string = message.author_name
else:
name_style = 'change-message-name'
header_style = 'change-message-header'
if message.author.email:
reviewer_string = "%s <%s>" % (
message.author.name,
message.author_name,
message.author.email)
else:
reviewer_string = message.author.name
reviewer_string = message.author_name
text = [(name_style, reviewer_string),
(header_style, ': '+lines.pop(0)),
@ -591,18 +591,17 @@ class ChangeView(urwid.WidgetWrap):
missing_revisions = set()
change_number = None
change_id = None
shas = set()
with self.app.db.getSession() as session:
change = session.getChange(self.change_key)
change_project_name = change.project.name
change_number = change.number
change_id = change.id
repo = gitrepo.get_repo(change.project.name, self.app.config)
for revision in change.revisions:
if not repo.hasCommit(revision.parent):
missing_revisions.add(revision.parent)
if not repo.hasCommit(revision.commit):
missing_revisions.add(revision.commit)
if missing_revisions:
break
shas.add(revision.parent)
shas.add(revision.commit)
repo = gitrepo.get_repo(change_project_name, self.app.config)
missing_revisions = repo.checkCommits(shas)
if missing_revisions:
if self.app.sync.offline:
raise gertty.view.DisplayError("Git commits not present in local repository")

Loading…
Cancel
Save