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
This commit is contained in:
parent
cf701e45c1
commit
cb12ada037
@ -259,15 +259,17 @@ class Repo(object):
|
|||||||
raise GitCloneError("No URL available for git clone")
|
raise GitCloneError("No URL available for git clone")
|
||||||
git.Repo.clone_from(self.url, self.path)
|
git.Repo.clone_from(self.url, self.path)
|
||||||
|
|
||||||
def hasCommit(self, sha):
|
def checkCommits(self, shas):
|
||||||
|
invalid = set()
|
||||||
repo = git.Repo(self.path)
|
repo = git.Repo(self.path)
|
||||||
try:
|
for sha in shas:
|
||||||
repo.commit(sha)
|
try:
|
||||||
except gitdb.exc.BadObject:
|
repo.commit(sha)
|
||||||
return False
|
except gitdb.exc.BadObject:
|
||||||
except ValueError:
|
invalid.add(sha)
|
||||||
return False
|
except ValueError:
|
||||||
return True
|
invalid.add(sha)
|
||||||
|
return invalid
|
||||||
|
|
||||||
def fetch(self, url, refspec):
|
def fetch(self, url, refspec):
|
||||||
repo = git.Repo(self.path)
|
repo = git.Repo(self.path)
|
||||||
|
@ -989,8 +989,7 @@ class CheckRevisionsTask(Task):
|
|||||||
for change in project.open_changes:
|
for change in project.open_changes:
|
||||||
if repo:
|
if repo:
|
||||||
for revision in change.revisions:
|
for revision in change.revisions:
|
||||||
if not (repo.hasCommit(revision.parent) and
|
if repo.checkCommits([revision.parent, revision.commit]):
|
||||||
repo.hasCommit(revision.commit)):
|
|
||||||
to_sync.add(change.id)
|
to_sync.add(change.id)
|
||||||
else:
|
else:
|
||||||
to_sync.add(change.id)
|
to_sync.add(change.id)
|
||||||
|
@ -415,16 +415,16 @@ class ChangeMessageBox(mywid.HyperText):
|
|||||||
if message.author.username == self.app.config.username:
|
if message.author.username == self.app.config.username:
|
||||||
name_style = 'change-message-own-name'
|
name_style = 'change-message-own-name'
|
||||||
header_style = 'change-message-own-header'
|
header_style = 'change-message-own-header'
|
||||||
reviewer_string = message.author.name
|
reviewer_string = message.author_name
|
||||||
else:
|
else:
|
||||||
name_style = 'change-message-name'
|
name_style = 'change-message-name'
|
||||||
header_style = 'change-message-header'
|
header_style = 'change-message-header'
|
||||||
if message.author.email:
|
if message.author.email:
|
||||||
reviewer_string = "%s <%s>" % (
|
reviewer_string = "%s <%s>" % (
|
||||||
message.author.name,
|
message.author_name,
|
||||||
message.author.email)
|
message.author.email)
|
||||||
else:
|
else:
|
||||||
reviewer_string = message.author.name
|
reviewer_string = message.author_name
|
||||||
|
|
||||||
text = [(name_style, reviewer_string),
|
text = [(name_style, reviewer_string),
|
||||||
(header_style, ': '+lines.pop(0)),
|
(header_style, ': '+lines.pop(0)),
|
||||||
@ -591,18 +591,17 @@ class ChangeView(urwid.WidgetWrap):
|
|||||||
missing_revisions = set()
|
missing_revisions = set()
|
||||||
change_number = None
|
change_number = None
|
||||||
change_id = None
|
change_id = None
|
||||||
|
shas = set()
|
||||||
with self.app.db.getSession() as session:
|
with self.app.db.getSession() as session:
|
||||||
change = session.getChange(self.change_key)
|
change = session.getChange(self.change_key)
|
||||||
|
change_project_name = change.project.name
|
||||||
change_number = change.number
|
change_number = change.number
|
||||||
change_id = change.id
|
change_id = change.id
|
||||||
repo = gitrepo.get_repo(change.project.name, self.app.config)
|
|
||||||
for revision in change.revisions:
|
for revision in change.revisions:
|
||||||
if not repo.hasCommit(revision.parent):
|
shas.add(revision.parent)
|
||||||
missing_revisions.add(revision.parent)
|
shas.add(revision.commit)
|
||||||
if not repo.hasCommit(revision.commit):
|
repo = gitrepo.get_repo(change_project_name, self.app.config)
|
||||||
missing_revisions.add(revision.commit)
|
missing_revisions = repo.checkCommits(shas)
|
||||||
if missing_revisions:
|
|
||||||
break
|
|
||||||
if missing_revisions:
|
if missing_revisions:
|
||||||
if self.app.sync.offline:
|
if self.app.sync.offline:
|
||||||
raise gertty.view.DisplayError("Git commits not present in local repository")
|
raise gertty.view.DisplayError("Git commits not present in local repository")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user