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
tags/1.6.0
James E. Blair 1 year ago
parent
commit
cb12ada037
3 changed files with 20 additions and 20 deletions
  1. 10
    8
      gertty/gitrepo.py
  2. 1
    2
      gertty/sync.py
  3. 9
    10
      gertty/view/change.py

+ 10
- 8
gertty/gitrepo.py View File

@@ -259,15 +259,17 @@ class Repo(object):
259 259
                 raise GitCloneError("No URL available for git clone")
260 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 264
         repo = git.Repo(self.path)
264
-        try:
265
-            repo.commit(sha)
266
-        except gitdb.exc.BadObject:
267
-            return False
268
-        except ValueError:
269
-            return False
270
-        return True
265
+        for sha in shas:
266
+            try:
267
+                repo.commit(sha)
268
+            except gitdb.exc.BadObject:
269
+                invalid.add(sha)
270
+            except ValueError:
271
+                invalid.add(sha)
272
+        return invalid
271 273
 
272 274
     def fetch(self, url, refspec):
273 275
         repo = git.Repo(self.path)

+ 1
- 2
gertty/sync.py View File

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

+ 9
- 10
gertty/view/change.py View File

@@ -415,16 +415,16 @@ class ChangeMessageBox(mywid.HyperText):
415 415
         if message.author.username == self.app.config.username:
416 416
             name_style = 'change-message-own-name'
417 417
             header_style = 'change-message-own-header'
418
-            reviewer_string = message.author.name
418
+            reviewer_string = message.author_name
419 419
         else:
420 420
             name_style = 'change-message-name'
421 421
             header_style = 'change-message-header'
422 422
             if message.author.email:
423 423
                 reviewer_string = "%s <%s>" % (
424
-                    message.author.name,
424
+                    message.author_name,
425 425
                     message.author.email)
426 426
             else:
427
-                reviewer_string = message.author.name
427
+                reviewer_string = message.author_name
428 428
 
429 429
         text = [(name_style, reviewer_string),
430 430
                 (header_style, ': '+lines.pop(0)),
@@ -591,18 +591,17 @@ class ChangeView(urwid.WidgetWrap):
591 591
         missing_revisions = set()
592 592
         change_number = None
593 593
         change_id = None
594
+        shas = set()
594 595
         with self.app.db.getSession() as session:
595 596
             change = session.getChange(self.change_key)
597
+            change_project_name = change.project.name
596 598
             change_number = change.number
597 599
             change_id = change.id
598
-            repo = gitrepo.get_repo(change.project.name, self.app.config)
599 600
             for revision in change.revisions:
600
-                if not repo.hasCommit(revision.parent):
601
-                    missing_revisions.add(revision.parent)
602
-                if not repo.hasCommit(revision.commit):
603
-                    missing_revisions.add(revision.commit)
604
-                if missing_revisions:
605
-                    break
601
+                shas.add(revision.parent)
602
+                shas.add(revision.commit)
603
+        repo = gitrepo.get_repo(change_project_name, self.app.config)
604
+        missing_revisions = repo.checkCommits(shas)
606 605
         if missing_revisions:
607 606
             if self.app.sync.offline:
608 607
                 raise gertty.view.DisplayError("Git commits not present in local repository")

Loading…
Cancel
Save