← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/preloadSpecificBuild-sort into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/preloadSpecificBuild-sort into lp:launchpad.

Commit message:
Fix BuildQueueSet.preloadSpecificBuild to preload each type only once, by sorting before groupby.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/preloadSpecificBuild-sort/+merge/224098

sort before grouping in BuildQueueSet.preloadSpecificBuild to ensure that we only preload once for each type. This stops BuilderSet:+index from duplicating queries when it encounters an SPRB in the middle of a group of BPBs, for example.
-- 
https://code.launchpad.net/~wgrant/launchpad/preloadSpecificBuild-sort/+merge/224098
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/preloadSpecificBuild-sort into lp:launchpad.
=== modified file 'lib/lp/buildmaster/model/buildqueue.py'
--- lib/lp/buildmaster/model/buildqueue.py	2014-06-20 06:14:09 +0000
+++ lib/lp/buildmaster/model/buildqueue.py	2014-06-23 10:44:05 +0000
@@ -127,10 +127,10 @@
         load_related(BuildFarmJob, queues, ['_build_farm_job_id'])
         bfj_to_bq = dict((bq._build_farm_job, bq) for bq in queues)
         key = attrgetter('_build_farm_job.job_type')
-        for job_type, grouped_queues in groupby(queues, key=key):
+        for job_type, group in groupby(sorted(queues, key=key), key=key):
             source = getUtility(ISpecificBuildFarmJobSource, job_type.name)
             builds = source.getByBuildFarmJobs(
-                [bq._build_farm_job for bq in grouped_queues])
+                [bq._build_farm_job for bq in group])
             for build in builds:
                 bq = bfj_to_bq[removeSecurityProxy(build).build_farm_job]
                 get_property_cache(bq).specific_build = build

=== modified file 'lib/lp/soyuz/browser/tests/test_builder.py'
--- lib/lp/soyuz/browser/tests/test_builder.py	2013-11-14 09:46:03 +0000
+++ lib/lp/soyuz/browser/tests/test_builder.py	2014-06-23 10:44:05 +0000
@@ -71,3 +71,18 @@
         recorder1, recorder2 = record_two_runs(
             builders_homepage_render, create_build, nb_objects)
         self.assertThat(recorder2, HasQueryCount(Equals(recorder1.count)))
+
+    def test_builders_variety_query_count(self):
+        def create_builds():
+            bqs = [
+                self.factory.makeBinaryPackageBuild().queueBuild(),
+                self.factory.makeSourcePackageRecipeBuild().queueBuild(),
+                self.factory.makeTranslationTemplatesBuild().queueBuild(),
+                ]
+            for bq in bqs:
+                bq.markAsBuilding(self.factory.makeBuilder())
+
+        nb_objects = 2
+        recorder1, recorder2 = record_two_runs(
+            builders_homepage_render, create_builds, nb_objects)
+        self.assertThat(recorder2, HasQueryCount(Equals(recorder1.count)))


Follow ups