summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2017-08-24 13:10:25 -0700
committerJames E. Blair <jeblair@redhat.com>2017-08-24 13:18:33 -0700
commitcb12ada037b98401fb1388e527595c2eb877134e (patch)
tree4cbe2f4e00e166a201d0265492c685f784519bea
parentcf701e45c18d4b241ce7f295947fa276db4c1a5d (diff)
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
Notes
Notes (review): Code-Review+2: James E. Blair <corvus@inaugust.com> Workflow+1: James E. Blair <corvus@inaugust.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 28 Aug 2017 16:00:55 +0000 Reviewed-on: https://review.openstack.org/497600 Project: openstack/gertty Branch: refs/heads/master
-rw-r--r--gertty/gitrepo.py18
-rw-r--r--gertty/sync.py3
-rw-r--r--gertty/view/change.py19
3 files changed, 20 insertions, 20 deletions
diff --git a/gertty/gitrepo.py b/gertty/gitrepo.py
index 4aed83e..e2e20d2 100644
--- a/gertty/gitrepo.py
+++ b/gertty/gitrepo.py
@@ -259,15 +259,17 @@ class Repo(object):
259 raise GitCloneError("No URL available for git clone") 259 raise GitCloneError("No URL available for git clone")
260 git.Repo.clone_from(self.url, self.path) 260 git.Repo.clone_from(self.url, self.path)
261 261
262 def hasCommit(self, sha): 262 def checkCommits(self, shas):
263 invalid = set()
263 repo = git.Repo(self.path) 264 repo = git.Repo(self.path)
264 try: 265 for sha in shas:
265 repo.commit(sha) 266 try:
266 except gitdb.exc.BadObject: 267 repo.commit(sha)
267 return False 268 except gitdb.exc.BadObject:
268 except ValueError: 269 invalid.add(sha)
269 return False 270 except ValueError:
270 return True 271 invalid.add(sha)
272 return invalid
271 273
272 def fetch(self, url, refspec): 274 def fetch(self, url, refspec):
273 repo = git.Repo(self.path) 275 repo = git.Repo(self.path)
diff --git a/gertty/sync.py b/gertty/sync.py
index fc58c1a..b504ece 100644
--- a/gertty/sync.py
+++ b/gertty/sync.py
@@ -989,8 +989,7 @@ class CheckRevisionsTask(Task):
989 for change in project.open_changes: 989 for change in project.open_changes:
990 if repo: 990 if repo:
991 for revision in change.revisions: 991 for revision in change.revisions:
992 if not (repo.hasCommit(revision.parent) and 992 if repo.checkCommits([revision.parent, revision.commit]):
993 repo.hasCommit(revision.commit)):
994 to_sync.add(change.id) 993 to_sync.add(change.id)
995 else: 994 else:
996 to_sync.add(change.id) 995 to_sync.add(change.id)
diff --git a/gertty/view/change.py b/gertty/view/change.py
index 9a575f2..5cebed6 100644
--- a/gertty/view/change.py
+++ b/gertty/view/change.py
@@ -415,16 +415,16 @@ class ChangeMessageBox(mywid.HyperText):
415 if message.author.username == self.app.config.username: 415 if message.author.username == self.app.config.username:
416 name_style = 'change-message-own-name' 416 name_style = 'change-message-own-name'
417 header_style = 'change-message-own-header' 417 header_style = 'change-message-own-header'
418 reviewer_string = message.author.name 418 reviewer_string = message.author_name
419 else: 419 else:
420 name_style = 'change-message-name' 420 name_style = 'change-message-name'
421 header_style = 'change-message-header' 421 header_style = 'change-message-header'
422 if message.author.email: 422 if message.author.email:
423 reviewer_string = "%s <%s>" % ( 423 reviewer_string = "%s <%s>" % (
424 message.author.name, 424 message.author_name,
425 message.author.email) 425 message.author.email)
426 else: 426 else:
427 reviewer_string = message.author.name 427 reviewer_string = message.author_name
428 428
429 text = [(name_style, reviewer_string), 429 text = [(name_style, reviewer_string),
430 (header_style, ': '+lines.pop(0)), 430 (header_style, ': '+lines.pop(0)),
@@ -591,18 +591,17 @@ class ChangeView(urwid.WidgetWrap):
591 missing_revisions = set() 591 missing_revisions = set()
592 change_number = None 592 change_number = None
593 change_id = None 593 change_id = None
594 shas = set()
594 with self.app.db.getSession() as session: 595 with self.app.db.getSession() as session:
595 change = session.getChange(self.change_key) 596 change = session.getChange(self.change_key)
597 change_project_name = change.project.name
596 change_number = change.number 598 change_number = change.number
597 change_id = change.id 599 change_id = change.id
598 repo = gitrepo.get_repo(change.project.name, self.app.config)
599 for revision in change.revisions: 600 for revision in change.revisions:
600 if not repo.hasCommit(revision.parent): 601 shas.add(revision.parent)
601 missing_revisions.add(revision.parent) 602 shas.add(revision.commit)
602 if not repo.hasCommit(revision.commit): 603 repo = gitrepo.get_repo(change_project_name, self.app.config)
603 missing_revisions.add(revision.commit) 604 missing_revisions = repo.checkCommits(shas)
604 if missing_revisions:
605 break
606 if missing_revisions: 605 if missing_revisions:
607 if self.app.sync.offline: 606 if self.app.sync.offline:
608 raise gertty.view.DisplayError("Git commits not present in local repository") 607 raise gertty.view.DisplayError("Git commits not present in local repository")