Merge lp:~cjwatson/launchpad/recipe-build-ordering into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18587
Proposed branch: lp:~cjwatson/launchpad/recipe-build-ordering
Merge into: lp:launchpad
Diff against target: 70 lines (+23/-6)
2 files modified
lib/lp/code/model/sourcepackagerecipe.py (+9/-6)
lib/lp/code/model/tests/test_sourcepackagerecipe.py (+14/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/recipe-build-ordering
Reviewer Review Type Date Requested Status
William Grant code Approve
Vincent Ladeuil (community) hug Approve
Review via email: mp+340534@code.launchpad.net

Commit message

Sort cancelled-before-starting recipe builds to the end of the build history.

Description of the change

These queries will be a little slower until the corresponding database branch lands, but they do well enough with other indexes that we don't need to coordinate that too carefully.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

And the world is a better place...
Thanks ;)

Revision history for this message
Vincent Ladeuil (vila) :
review: Approve (hug)
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/model/sourcepackagerecipe.py'
--- lib/lp/code/model/sourcepackagerecipe.py 2016-10-14 16:16:18 +0000
+++ lib/lp/code/model/sourcepackagerecipe.py 2018-03-02 18:02:05 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the1# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Implementation of the `SourcePackageRecipe` content type."""4"""Implementation of the `SourcePackageRecipe` content type."""
@@ -67,7 +67,10 @@
67 IMasterStore,67 IMasterStore,
68 IStore,68 IStore,
69 )69 )
70from lp.services.database.stormexpr import Greatest70from lp.services.database.stormexpr import (
71 Greatest,
72 NullsLast,
73 )
71from lp.services.propertycache import (74from lp.services.propertycache import (
72 cachedproperty,75 cachedproperty,
73 get_property_cache,76 get_property_cache,
@@ -330,9 +333,9 @@
330 def builds(self):333 def builds(self):
331 """See `ISourcePackageRecipe`."""334 """See `ISourcePackageRecipe`."""
332 order_by = (335 order_by = (
333 Desc(Greatest(336 NullsLast(Desc(Greatest(
334 SourcePackageRecipeBuild.date_started,337 SourcePackageRecipeBuild.date_started,
335 SourcePackageRecipeBuild.date_finished)),338 SourcePackageRecipeBuild.date_finished))),
336 Desc(SourcePackageRecipeBuild.date_created),339 Desc(SourcePackageRecipeBuild.date_created),
337 Desc(SourcePackageRecipeBuild.id))340 Desc(SourcePackageRecipeBuild.id))
338 return self._getBuilds(None, order_by)341 return self._getBuilds(None, order_by)
@@ -343,9 +346,9 @@
343 filter_term = (346 filter_term = (
344 SourcePackageRecipeBuild.status != BuildStatus.NEEDSBUILD)347 SourcePackageRecipeBuild.status != BuildStatus.NEEDSBUILD)
345 order_by = (348 order_by = (
346 Desc(Greatest(349 NullsLast(Desc(Greatest(
347 SourcePackageRecipeBuild.date_started,350 SourcePackageRecipeBuild.date_started,
348 SourcePackageRecipeBuild.date_finished)),351 SourcePackageRecipeBuild.date_finished))),
349 Desc(SourcePackageRecipeBuild.id))352 Desc(SourcePackageRecipeBuild.id))
350 return self._getBuilds(filter_term, order_by)353 return self._getBuilds(filter_term, order_by)
351354
352355
=== modified file 'lib/lp/code/model/tests/test_sourcepackagerecipe.py'
--- lib/lp/code/model/tests/test_sourcepackagerecipe.py 2017-10-04 01:53:48 +0000
+++ lib/lp/code/model/tests/test_sourcepackagerecipe.py 2018-03-02 18:02:05 +0000
@@ -765,6 +765,20 @@
765 self.assertEqual([build], list(recipe.completed_builds))765 self.assertEqual([build], list(recipe.completed_builds))
766 self.assertEqual([], list(recipe.pending_builds))766 self.assertEqual([], list(recipe.pending_builds))
767767
768 def test_getBuilds_cancelled_never_started_last(self):
769 # A cancelled build that was never even started sorts to the end.
770 recipe = self.makeSourcePackageRecipe()
771 fullybuilt = self.factory.makeSourcePackageRecipeBuild(recipe=recipe)
772 instacancelled = self.factory.makeSourcePackageRecipeBuild(
773 recipe=recipe)
774 fullybuilt.updateStatus(BuildStatus.BUILDING)
775 fullybuilt.updateStatus(BuildStatus.CANCELLED)
776 instacancelled.updateStatus(BuildStatus.CANCELLED)
777 self.assertEqual([fullybuilt, instacancelled], list(recipe.builds))
778 self.assertEqual(
779 [fullybuilt, instacancelled], list(recipe.completed_builds))
780 self.assertEqual([], list(recipe.pending_builds))
781
768 def test_setRecipeText_private_base_branch(self):782 def test_setRecipeText_private_base_branch(self):
769 source_package_recipe = self.makeSourcePackageRecipe()783 source_package_recipe = self.makeSourcePackageRecipe()
770 with person_logged_in(source_package_recipe.owner):784 with person_logged_in(source_package_recipe.owner):