launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27061
[Merge] ~ilasc/launchpad:number-of-repack-candidates into launchpad:master
Ioana Lasc has proposed merging ~ilasc/launchpad:number-of-repack-candidates into launchpad:master.
Commit message:
GET total number of repack candidates
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~ilasc/launchpad/+git/launchpad/+merge/402818
This adds an endpoint that gives us the total number of repositories that qualify for a repack.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:number-of-repack-candidates into launchpad:master.
diff --git a/lib/lp/code/interfaces/gitrepository.py b/lib/lp/code/interfaces/gitrepository.py
index 294cc35..a6d054f 100644
--- a/lib/lp/code/interfaces/gitrepository.py
+++ b/lib/lp/code/interfaces/gitrepository.py
@@ -1096,6 +1096,15 @@ class IGitRepositorySet(Interface):
:return: A collection of `IGitRepository` objects.
"""
+ @export_read_operation()
+ @operation_for_version("devel")
+ def getNumberRepositoriesForRepack():
+ """Get number of repositories qualifying for a repack.
+
+ :return: The number of `IGitRepository` objects qualifying
+ for a repack.
+ """
+
@call_with(user=REQUEST_USER)
@operation_parameters(
person=Reference(
diff --git a/lib/lp/code/model/gitrepository.py b/lib/lp/code/model/gitrepository.py
index 2ba9491..f97c696 100644
--- a/lib/lp/code/model/gitrepository.py
+++ b/lib/lp/code/model/gitrepository.py
@@ -1859,6 +1859,20 @@ class GitRepositorySet:
collection = collection.modifiedSince(modified_since_date)
return collection.getRepositories(eager_load=True, sort_by=order_by)
+ def getNumberRepositoriesForRepack(self):
+ """See `IGitRepositorySet`."""
+ repos = IStore(GitRepository).find(
+ GitRepository,
+ Or(
+ GitRepository.loose_object_count >=
+ config.codehosting.loose_objects_threshold,
+ GitRepository.pack_count >=
+ config.codehosting.packs_threshold,
+ ),
+ GitRepository.status == GitRepositoryStatus.AVAILABLE,
+ ).order_by(GitRepository.id)
+ return len(list(repos))
+
def getRepositoryVisibilityInfo(self, user, person, repository_names):
"""See `IGitRepositorySet`."""
if user is None:
diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
index 008c640..bcb931a 100644
--- a/lib/lp/code/model/tests/test_gitrepository.py
+++ b/lib/lp/code/model/tests/test_gitrepository.py
@@ -4069,6 +4069,31 @@ class TestGitRepositoryWebservice(TestCaseWithFactory):
def test_getRepositories_personal(self):
self.assertGetRepositoriesWorks(self.factory.makePerson())
+ def test_getNumberRepositoriesForRepack(self):
+ person = self.factory.makePerson()
+ webservice = webservice_for_person(
+ person, permission=OAuthPermission.WRITE_PUBLIC)
+ webservice.default_api_version = "devel"
+ response = webservice.named_get(
+ "/+git", "getNumberRepositoriesForRepack")
+ self.assertEqual(200, response.status)
+ self.assertEqual(0, response.jsonBody())
+ with person_logged_in(person):
+ repo = []
+ for i in range(5):
+ repo.append(self.factory.makeGitRepository())
+ for i in range(3):
+ repo.append(self.factory.makeGitRepository())
+ repo[i] = removeSecurityProxy(repo[i])
+ repo[i].loose_object_count = 7000
+ repo[i].pack_count = 43
+
+ # We have a total of 3 candidates now
+ response = webservice.named_get(
+ "/+git", "getNumberRepositoriesForRepack")
+ self.assertEqual(200, response.status)
+ self.assertEqual(3, response.jsonBody())
+
def test_get_without_default_branch(self):
# Ensure we're not getting an error when calling
# GET on the Webservice when a Git Repo exists in the DB