# HG changeset patch
# User Mathias De Mare <[email protected]>
# Date 1669726298 -3600
#      Tue Nov 29 13:51:38 2022 +0100
# Node ID 2a5de196e40454dc9437e31e2224c183779a61d9
# Parent  7037365a7bc351b81f05c790c6d3417d81d7bd5d
kallithea pullrequests: allow limiting the number of additional changes shown

We've noticed some scalability issues when many descendants exist
for the changesets in a pull request.
If we limit the number of proposed changesets to add to the review,
we no longer overwhelm Kallithea in this case.

(This occurred because we were merging a lot of heads in the repository.)

diff --git a/kallithea/controllers/pullrequests.py 
b/kallithea/controllers/pullrequests.py
--- a/kallithea/controllers/pullrequests.py
+++ b/kallithea/controllers/pullrequests.py
@@ -30,6 +30,7 @@ import traceback
 
 import formencode
 import mercurial.unionrepo
+import tg
 from tg import request
 from tg import tmpl_context as c
 from tg.i18n import ugettext as _
@@ -68,6 +69,14 @@ def _get_reviewer(user_id):
 
     return user
 
+def _filter_additional_changes_revs(revs):
+    """Allow hooking in to filter out some of the additional changes."""
+    additional_changes_rev_limit = 
tg.config.get('additional_changes_rev_limit')
+    if additional_changes_rev_limit and 
additional_changes_rev_limit.isnumeric():
+        new_revs = list(revs)
+        return new_revs[-int(additional_changes_rev_limit):]
+    else:
+        return revs
 
 class PullrequestsController(base.BaseRepoController):
 
@@ -523,6 +532,7 @@ class PullrequestsController(base.BaseRe
                 else: # look for descendants of PR head on source branch in 
org repo
                     avail_revs = org_scm_instance._repo.revs('%s:: & 
branch(%s)',
                                                              revs[0], 
c.cs_branch_name)
+                    avail_revs = _filter_additional_changes_revs(avail_revs)
                     if len(avail_revs) > 1: # more than just revs[0]
                         # also show changesets that not are descendants but 
would be merged in
                         targethead = 
other_scm_instance.get_changeset(c.a_branch_name).raw_id
@@ -537,6 +547,7 @@ class PullrequestsController(base.BaseRe
                             hgrepo = org_scm_instance._repo
                         show = set(hgrepo.revs('::%ld & !::parents(%s) & 
!::%s',
                                                avail_revs, revs[0], 
targethead))
+                        show = _filter_additional_changes_revs(show)
                         if show:
                             c.update_msg = _('The following additional changes 
are available on %s:') % c.cs_branch_name
                         else:
diff --git a/kallithea/tests/functional/test_pullrequests.py 
b/kallithea/tests/functional/test_pullrequests.py
--- a/kallithea/tests/functional/test_pullrequests.py
+++ b/kallithea/tests/functional/test_pullrequests.py
@@ -1,7 +1,9 @@
 import re
 
+import mock
 import pytest
 
+import kallithea.controllers
 from kallithea.controllers.pullrequests import PullrequestsController
 from kallithea.model import db, meta
 from kallithea.tests import base
@@ -390,3 +392,18 @@ class TestPullrequestsGetRepoRefs(base.T
                 content='line1\n', message='commit1', vcs_type='hg',
                 parent=None, newfile=True)
         # TODO
+
+class TestPullrequests(base.TestController):
+
+    def test_filter_additional_changes_no_rev_limit(self):
+        config_mock = {
+        }
+        with mock.patch('tg.config', config_mock):
+            assert 
len(kallithea.controllers.pullrequests._filter_additional_changes_revs(["1", 
"2", "3", "4"])) == 4
+
+    def test_filter_additional_changes_rev_limit(self):
+        config_mock = {
+            'additional_changes_rev_limit': "2",
+        }
+        with mock.patch('tg.config', config_mock):
+            assert 
len(kallithea.controllers.pullrequests._filter_additional_changes_revs(["1", 
"2", "3", "4"])) == 2

_______________________________________________
kallithea-general mailing list
[email protected]
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general

Reply via email to