launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26687
[Merge] ~ilasc/launchpad:add-repack-stats-api into launchpad:master
Ioana Lasc has proposed merging ~ilasc/launchpad:add-repack-stats-api into launchpad:master.
Commit message:
Add API to see repack stats for one repo
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~ilasc/launchpad/+git/launchpad/+merge/399851
I think the quickest and less computationally expensive way for us to have some visibility into repack data for a repository at the moment is an API.
The proposed endpoint might not be optimal but I figured proposing an attempt via code might be the easiest way for us to start discussing / refining a reasonable approach to this.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:add-repack-stats-api into launchpad:master.
diff --git a/lib/lp/code/interfaces/gitrepository.py b/lib/lp/code/interfaces/gitrepository.py
index 365f082..3a93595 100644
--- a/lib/lp/code/interfaces/gitrepository.py
+++ b/lib/lp/code/interfaces/gitrepository.py
@@ -843,6 +843,15 @@ class IGitRepositoryEdit(IWebhookTarget):
@export_read_operation()
@operation_for_version("devel")
+ def getRepackData():
+ """Return repack data for this repository.
+
+ :return: The number of loose objects and packs for this repository
+ and the dates it was last scanned and repacked.
+ """
+
+ @export_read_operation()
+ @operation_for_version("devel")
def getRules():
"""Get the access rules for this repository."""
diff --git a/lib/lp/code/model/gitrepository.py b/lib/lp/code/model/gitrepository.py
index 21a6f82..924ec7a 100644
--- a/lib/lp/code/model/gitrepository.py
+++ b/lib/lp/code/model/gitrepository.py
@@ -682,6 +682,14 @@ class GitRepository(StormBase, WebhookTargetMixin, GitIdentityMixin):
return ref
return None
+ def getRepackData(self):
+ result = dict()
+ result['loose_object_count'] = self.loose_object_count
+ result['pack_count'] = self.pack_count
+ result['date_last_repacked'] = self.date_last_repacked
+ result['date_last_scanned'] = self.date_last_scanned
+ return result
+
@staticmethod
def _convertRefInfo(info):
"""Validate and canonicalise ref info from the hosting service.
diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
index bdf636b..5e2ae60 100644
--- a/lib/lp/code/model/tests/test_gitrepository.py
+++ b/lib/lp/code/model/tests/test_gitrepository.py
@@ -3900,6 +3900,46 @@ class TestGitRepositoryWebservice(TestCaseWithFactory):
hosting_fixture.repackRepository.calls)
self.assertEqual(1, hosting_fixture.repackRepository.call_count)
+ def test_getRepackData_owner(self):
+
+ owner = self.factory.makePerson()
+ repo = self.factory.makeGitRepository(
+ owner=owner, name="repository")
+ repo_url = api_url(repo)
+
+ webservice = webservice_for_person(
+ owner, permission=OAuthPermission.WRITE_PUBLIC)
+ webservice.default_api_version = "devel"
+
+ response = webservice.named_get(
+ repo_url, "getRepackData")
+ self.assertEqual(200, response.status)
+ repository = response.jsonBody()
+ self.assertThat(repository, ContainsDict({
+ u'loose_object_count': Equals(None),
+ u'pack_count': Equals(None),
+ u'date_last_repacked': Equals(None),
+ u'date_last_scanned': Equals(None),
+ }))
+
+ utc_now = UTC_NOW
+ repo = removeSecurityProxy(repo)
+ repo.loose_object_count = 45
+ repo.pack_count = 523
+ repo.date_last_repacked = utc_now
+ repo.date_last_scanned = utc_now
+
+ response = webservice.named_get(
+ repo_url, "getRepackData")
+ self.assertEqual(200, response.status)
+ repository = response.jsonBody()
+ self.assertThat(repository, ContainsDict({
+ "loose_object_count": Equals(45),
+ "pack_count": Equals(523),
+ "date_last_repacked": Equals(utc_now),
+ "date_last_scanned": Equals(utc_now),
+ }))
+
def test_urls(self):
owner_db = self.factory.makePerson(name="person")
project_db = self.factory.makeProduct(name="project")