Merge lp:~wallyworld/launchpad/improve-latestpersonspr-garbo-job-1071581 into lp:launchpad

Proposed by Ian Booth
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 16249
Proposed branch: lp:~wallyworld/launchpad/improve-latestpersonspr-garbo-job-1071581
Merge into: lp:launchpad
Diff against target: 103 lines (+25/-7)
2 files modified
lib/lp/scripts/garbo.py (+15/-7)
lib/lp/scripts/tests/test_garbo.py (+10/-0)
To merge this branch: bzr merge lp:~wallyworld/launchpad/improve-latestpersonspr-garbo-job-1071581
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+133417@code.launchpad.net

Commit message

Improve PopulateLatestPersonSourcepackageReleaseCache so it only processes new spr records.

Description of the change

== Implementation ==

When I first wrote the garbo job, I didn't now that a new source package release record was created each time a package is uploaded. So the garbo job reset the next_id to 0 after each run, causing all spr's to eventually be reprocessed. This branch alters the job so that a separate, monotonically increasing next id is used for processing creator and maintainer records. Thus, the garbo job should eventually "catch" up to the releases and from then on do minimal work to maintain the report table.

== Tests ==

Update the test_PopulateLatestPersonSourcepackageReleaseCache to chec the job state.

== Lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/scripts/garbo.py
  lib/lp/scripts/tests/test_garbo.py

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Thanks, Ian.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/scripts/garbo.py'
2--- lib/lp/scripts/garbo.py 2012-11-05 11:32:27 +0000
3+++ lib/lp/scripts/garbo.py 2012-11-08 07:54:22 +0000
4@@ -478,13 +478,15 @@
5 self.store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR)
6 # Keep a record of the processed source package release id and data
7 # type (creator or maintainer) so we know where to job got up to.
8- self.next_id = 0
9+ self.next_id_for_creator = 0
10+ self.next_id_for_maintainer = 0
11 self.current_person_filter_type = 'creator'
12 self.starting_person_filter_type = self.current_person_filter_type
13 self.job_name = self.__class__.__name__
14 job_data = load_garbo_job_state(self.job_name)
15 if job_data:
16- self.next_id = job_data['next_id']
17+ self.next_id_for_creator = job_data['next_id_for_creator']
18+ self.next_id_for_maintainer = job_data['next_id_for_maintainer']
19 self.current_person_filter_type = job_data['person_filter_type']
20 self.starting_person_filter_type = self.current_person_filter_type
21
22@@ -493,8 +495,10 @@
23 # creator or maintainer as required.
24 if self.current_person_filter_type == 'creator':
25 person_filter = SourcePackageRelease.creatorID
26+ next_id = self.next_id_for_creator
27 else:
28 person_filter = SourcePackageRelease.maintainerID
29+ next_id = self.next_id_for_maintainer
30 spph = ClassAlias(SourcePackagePublishingHistory, "spph")
31 origin = [
32 SourcePackageRelease,
33@@ -504,7 +508,7 @@
34 spph.archiveID == SourcePackageRelease.upload_archiveID))]
35 spr_select = self.store.using(*origin).find(
36 (SourcePackageRelease.id, Alias(spph.id, 'spph_id')),
37- SourcePackageRelease.id > self.next_id
38+ SourcePackageRelease.id > next_id
39 ).order_by(
40 person_filter,
41 SourcePackageRelease.upload_distroseriesID,
42@@ -546,7 +550,6 @@
43 self.current_person_filter_type = 'maintainer'
44 else:
45 self.current_person_filter_type = 'creator'
46- self.next_id = 0
47 current_count = self.getPendingUpdates().count()
48 return current_count == 0
49
50@@ -601,17 +604,22 @@
51 self.store.execute(Insert(columns, values=inserts))
52
53 def __call__(self, chunk_size):
54- max_id = self.next_id
55+ max_id = None
56 updates = []
57 for update in (self.getPendingUpdates()[:chunk_size]):
58 updates.append(update)
59 max_id = update[0]
60 self.update_cache(updates)
61
62- self.next_id = max_id
63+ if max_id:
64+ if self.current_person_filter_type == 'creator':
65+ self.next_id_for_creator = max_id
66+ else:
67+ self.next_id_for_maintainer = max_id
68 self.store.flush()
69 save_garbo_job_state(self.job_name, {
70- 'next_id': max_id,
71+ 'next_id_for_creator': self.next_id_for_creator,
72+ 'next_id_for_maintainer': self.next_id_for_maintainer,
73 'person_filter_type': self.current_person_filter_type})
74 transaction.commit()
75
76
77=== modified file 'lib/lp/scripts/tests/test_garbo.py'
78--- lib/lp/scripts/tests/test_garbo.py 2012-11-07 12:38:19 +0000
79+++ lib/lp/scripts/tests/test_garbo.py 2012-11-08 07:54:22 +0000
80@@ -1205,6 +1205,11 @@
81 _assert_release_by_maintainer(maintainers[0], spr3)
82 _assert_release_by_maintainer(maintainers[1], spr4)
83
84+ job_data = load_garbo_job_state(
85+ 'PopulateLatestPersonSourcepackageReleaseCache')
86+ self.assertEqual(spr4.id, job_data['next_id_for_creator'])
87+ self.assertEqual(spr4.id, job_data['next_id_for_maintainer'])
88+
89 # Create a newer published source package release and ensure the
90 # release cache table is correctly updated.
91 switch_dbuser('testadmin')
92@@ -1224,6 +1229,11 @@
93 _assert_release_by_maintainer(maintainers[0], spr3)
94 _assert_release_by_maintainer(maintainers[1], spr5)
95
96+ job_data = load_garbo_job_state(
97+ 'PopulateLatestPersonSourcepackageReleaseCache')
98+ self.assertEqual(spr5.id, job_data['next_id_for_creator'])
99+ self.assertEqual(spr5.id, job_data['next_id_for_maintainer'])
100+
101
102 class TestGarboTasks(TestCaseWithFactory):
103 layer = LaunchpadZopelessLayer