Merge ~cjwatson/launchpad:sync-signingkeys-occasional-commit into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 1c909ab78f9a89fb6af8f34f484285fcb27dac61
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:sync-signingkeys-occasional-commit
Merge into: launchpad:master
Diff against target: 62 lines (+18/-4)
2 files modified
lib/lp/archivepublisher/scripts/sync_signingkeys.py (+14/-4)
lib/lp/archivepublisher/tests/test_sync_signingkeys.py (+4/-0)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+393173@code.launchpad.net

Commit message

sync-signingkeys: Commit after every 100th archive

Description of the change

With 130000 or so archives in production, committing after every archive was taking too long.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archivepublisher/scripts/sync_signingkeys.py b/lib/lp/archivepublisher/scripts/sync_signingkeys.py
2index f8d05f0..b3c4e72 100644
3--- a/lib/lp/archivepublisher/scripts/sync_signingkeys.py
4+++ b/lib/lp/archivepublisher/scripts/sync_signingkeys.py
5@@ -245,14 +245,24 @@ class SyncSigningKeysScript(LaunchpadScript):
6 secret_key_path, SigningKeyType.OPENPGP)
7 self.injectGPG(archive, secret_key_path)
8
9+ def _maybeCommit(self, count):
10+ if self.options.dry_run:
11+ transaction.abort()
12+ else:
13+ self.logger.info(
14+ "%d %s processed; committing.",
15+ count, "archive" if count == 1 else "archives")
16+ transaction.commit()
17+
18 def main(self):
19 archives = list(self.getArchives())
20+ total = 0
21 for i, archive in enumerate(archives):
22+ if i != 0 and i % 100 == 0:
23+ self._maybeCommit(i)
24 self.logger.debug(
25 "#%s - Processing keys for archive %s.", i, archive.reference)
26 self.processArchive(archive)
27- if self.options.dry_run:
28- transaction.abort()
29- else:
30- transaction.commit()
31+ total = i + 1
32+ self._maybeCommit(total)
33 self.logger.info("Finished processing archives injections.")
34diff --git a/lib/lp/archivepublisher/tests/test_sync_signingkeys.py b/lib/lp/archivepublisher/tests/test_sync_signingkeys.py
35index 4f410a2..7c54063 100644
36--- a/lib/lp/archivepublisher/tests/test_sync_signingkeys.py
37+++ b/lib/lp/archivepublisher/tests/test_sync_signingkeys.py
38@@ -279,6 +279,8 @@ class TestSyncSigningKeysScript(TestCaseWithFactory):
39 SigningKeyType.UEFI, None),
40 content)
41
42+ self.assertIn("INFO 1 archive processed; committing.", content)
43+
44 def test_process_archive_dry_run(self):
45 signing_service_client = self.useFixture(
46 SigningServiceClientFixture(self.factory))
47@@ -403,6 +405,7 @@ class TestSyncSigningKeysScript(TestCaseWithFactory):
48 "INFO Found key file %s (type=%s)." % (
49 secret_key_path, SigningKeyType.OPENPGP),
50 content)
51+ self.assertIn("INFO 1 archive processed; committing.", content)
52
53 def test_process_archive_openpgp_missing(self):
54 archive = self.factory.makeArchive()
55@@ -424,6 +427,7 @@ class TestSyncSigningKeysScript(TestCaseWithFactory):
56 "DEBUG #0 - Processing keys for archive %s." % archive.reference,
57 content)
58 self.assertNotIn("INFO Found key file", content)
59+ self.assertIn("INFO 1 archive processed; committing.", content)
60
61 def test_inject(self):
62 signing_service_client = self.useFixture(

Subscribers

People subscribed via source and target branches

to status/vote changes: