Merge ~ilasc/launchpad:add-repack-stats-api into launchpad:master

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 5b56401f928b9826cc81dd1e00d0d757de243595
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ilasc/launchpad:add-repack-stats-api
Merge into: launchpad:master
Diff against target: 72 lines (+50/-0)
2 files modified
lib/lp/code/interfaces/gitrepository.py (+17/-0)
lib/lp/code/model/tests/test_gitrepository.py (+33/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+399851@code.launchpad.net

Commit message

Add API to see repack stats for one repo

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

We could do this, but the attributes in question are just simple ints/datetimes and they aren't secret. Any reason not to just export them as read-only attributes on IGitRepository?

review: Needs Information
1ee7e3c... by Ioana Lasc

Expose repack data as read-only

Revision history for this message
Ioana Lasc (ilasc) wrote :

Agreed they could just be exposed on the interface as read-only attributes, done.

Revision history for this message
Colin Watson (cjwatson) wrote :

Thanks for the update! A few minor nits, but otherwise LGTM - go ahead and land this once you've fixed these.

review: Approve
5b56401... by Ioana Lasc

Make repack stats not required on interface

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 365f082..5374fb7 100644
3--- a/lib/lp/code/interfaces/gitrepository.py
4+++ b/lib/lp/code/interfaces/gitrepository.py
5@@ -216,6 +216,23 @@ class IGitRepositoryView(IHasRecipes):
6 shortened_path = Attribute(
7 "The shortest reasonable version of the path to this repository.")
8
9+ pack_count = exported(Int(
10+ title=_("Pack count"), readonly=True, required=False,
11+ description=_("The number of packs for this repository.")))
12+
13+ loose_object_count = exported(Int(
14+ title=_("Loose object count"), readonly=True, required=False,
15+ description=_("The number of loose objects for this repository.")))
16+
17+ date_last_repacked = exported(Datetime(
18+ title=_("Date last repacked"), readonly=True, required=False,
19+ description=_("The date that this repository was last repacked.")))
20+
21+ date_last_scanned = exported(Datetime(
22+ title=_("Date last scanned"), readonly=True, required=False,
23+ description=_("The date when pack statistics were last updated "
24+ "for this repository.")))
25+
26 def getClonedFrom():
27 """Returns from which repository the given repo is a clone from."""
28
29diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
30index bdf636b..6cec839 100644
31--- a/lib/lp/code/model/tests/test_gitrepository.py
32+++ b/lib/lp/code/model/tests/test_gitrepository.py
33@@ -3900,6 +3900,39 @@ class TestGitRepositoryWebservice(TestCaseWithFactory):
34 hosting_fixture.repackRepository.calls)
35 self.assertEqual(1, hosting_fixture.repackRepository.call_count)
36
37+ def test_repack_data(self):
38+ owner_db = self.factory.makePerson(name="person")
39+ project_db = self.factory.makeProduct(name="project")
40+ repository_db = self.factory.makeGitRepository(
41+ owner=owner_db, target=project_db, name="repository")
42+ webservice = webservice_for_person(
43+ repository_db.owner, permission=OAuthPermission.READ_PUBLIC)
44+ webservice.default_api_version = "devel"
45+ with person_logged_in(ANONYMOUS):
46+ repository_url = api_url(repository_db)
47+ repository = webservice.get(repository_url).jsonBody()
48+ self.assertThat(repository, ContainsDict({
49+ 'loose_object_count': Is(None),
50+ 'pack_count': Is(None),
51+ 'date_last_repacked': Is(None),
52+ 'date_last_scanned': Is(None),
53+ }))
54+
55+ repository_db = removeSecurityProxy(repository_db)
56+ repository_db.loose_object_count = 45
57+ repository_db.pack_count = 523
58+ repository_db.date_last_repacked = UTC_NOW
59+ repository_db.date_last_scanned = UTC_NOW
60+
61+ repository = webservice.get(repository_url).jsonBody()
62+
63+ self.assertThat(repository, ContainsDict({
64+ 'loose_object_count': Equals(45),
65+ 'pack_count': Equals(523),
66+ 'date_last_repacked': Equals(UTC_NOW),
67+ 'date_last_scanned': Equals(UTC_NOW),
68+ }))
69+
70 def test_urls(self):
71 owner_db = self.factory.makePerson(name="person")
72 project_db = self.factory.makeProduct(name="project")

Subscribers

People subscribed via source and target branches

to status/vote changes: