Merge ~ilasc/launchpad:number-of-repack-candidates into launchpad:master

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 83a536aa6e3dd41b39c8dd2f0855e302dc14d544
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ilasc/launchpad:number-of-repack-candidates
Merge into: launchpad:master
Diff against target: 79 lines (+46/-0)
3 files modified
lib/lp/code/interfaces/gitrepository.py (+9/-0)
lib/lp/code/model/gitrepository.py (+14/-0)
lib/lp/code/model/tests/test_gitrepository.py (+23/-0)
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+402818@code.launchpad.net

Commit message

GET total number of repack candidates

Description of the change

This adds an endpoint that gives us the total number of repositories that qualify for a repack.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
83a536a... by Ioana Lasc on 2021-05-20

Address code review comments

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/interfaces/gitrepository.py b/lib/lp/code/interfaces/gitrepository.py
2index 294cc35..dbd7870 100644
3--- a/lib/lp/code/interfaces/gitrepository.py
4+++ b/lib/lp/code/interfaces/gitrepository.py
5@@ -1096,6 +1096,15 @@ class IGitRepositorySet(Interface):
6 :return: A collection of `IGitRepository` objects.
7 """
8
9+ @export_read_operation()
10+ @operation_for_version("devel")
11+ def countRepositoriesForRepack():
12+ """Get number of repositories qualifying for a repack.
13+
14+ :return: The number of `IGitRepository` objects qualifying
15+ for a repack.
16+ """
17+
18 @call_with(user=REQUEST_USER)
19 @operation_parameters(
20 person=Reference(
21diff --git a/lib/lp/code/model/gitrepository.py b/lib/lp/code/model/gitrepository.py
22index d447abb..58c298c 100644
23--- a/lib/lp/code/model/gitrepository.py
24+++ b/lib/lp/code/model/gitrepository.py
25@@ -1862,6 +1862,20 @@ class GitRepositorySet:
26 collection = collection.modifiedSince(modified_since_date)
27 return collection.getRepositories(eager_load=True, sort_by=order_by)
28
29+ def countRepositoriesForRepack(self):
30+ """See `IGitRepositorySet`."""
31+ repos = IStore(GitRepository).find(
32+ GitRepository,
33+ Or(
34+ GitRepository.loose_object_count >=
35+ config.codehosting.loose_objects_threshold,
36+ GitRepository.pack_count >=
37+ config.codehosting.packs_threshold,
38+ ),
39+ GitRepository.status == GitRepositoryStatus.AVAILABLE,
40+ ).order_by(GitRepository.id)
41+ return repos.count()
42+
43 def getRepositoryVisibilityInfo(self, user, person, repository_names):
44 """See `IGitRepositorySet`."""
45 if user is None:
46diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
47index 008c640..a0d0baa 100644
48--- a/lib/lp/code/model/tests/test_gitrepository.py
49+++ b/lib/lp/code/model/tests/test_gitrepository.py
50@@ -4069,6 +4069,29 @@ class TestGitRepositoryWebservice(TestCaseWithFactory):
51 def test_getRepositories_personal(self):
52 self.assertGetRepositoriesWorks(self.factory.makePerson())
53
54+ def test_getNumberRepositoriesForRepack(self):
55+ person = self.factory.makePerson()
56+ webservice = webservice_for_person(
57+ person, permission=OAuthPermission.WRITE_PUBLIC)
58+ webservice.default_api_version = "devel"
59+ response = webservice.named_get(
60+ "/+git", "countRepositoriesForRepack")
61+ self.assertEqual(200, response.status)
62+ self.assertEqual(0, response.jsonBody())
63+ with person_logged_in(person):
64+ for _ in range(5):
65+ self.factory.makeGitRepository()
66+ for _ in range(3):
67+ repo = self.factory.makeGitRepository()
68+ removeSecurityProxy(repo).loose_object_count = 7000
69+ removeSecurityProxy(repo).pack_count = 43
70+
71+ # We have a total of 3 candidates now
72+ response = webservice.named_get(
73+ "/+git", "countRepositoriesForRepack")
74+ self.assertEqual(200, response.status)
75+ self.assertEqual(3, response.jsonBody())
76+
77 def test_get_without_default_branch(self):
78 # Ensure we're not getting an error when calling
79 # GET on the Webservice when a Git Repo exists in the DB

Subscribers

People subscribed via source and target branches

to status/vote changes: