Merge lp:~rvb/launchpad/builder-history-lfa into lp:launchpad

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 14654
Proposed branch: lp:~rvb/launchpad/builder-history-lfa
Merge into: lp:launchpad
Prerequisite: lp:~rvb/launchpad/builder-history-bug-890326
Diff against target: 145 lines (+40/-22)
4 files modified
lib/lp/code/model/sourcepackagerecipebuild.py (+4/-0)
lib/lp/soyuz/browser/tests/test_builder.py (+1/-1)
lib/lp/soyuz/browser/tests/test_builder_views.py (+16/-9)
lib/lp/translations/model/translationtemplatesbuild.py (+19/-12)
To merge this branch: bzr merge lp:~rvb/launchpad/builder-history-lfa
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+86071@code.launchpad.net

Commit message

[r=adeuring][bug=905380] Prefetch LibraryFileAlias objects.

Description of the change

This branch adds the prefetching of LibraryFileAlias objects to {sourcepackagerecipebuild, translationtemplatesbuild}preloadBuildsData.

= Tests =
(modified tests)
./bin/test -vvc test_builder_views test_build_history

= Q/A =
Find a builder/+history page and make sure that this query http://paste.ubuntu.com/772360/ is not among the repeated statements.

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) :
review: Approve (code)
Revision history for this message
Abel Deuring (adeuring) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/sourcepackagerecipebuild.py'
2--- lib/lp/code/model/sourcepackagerecipebuild.py 2012-01-02 11:21:14 +0000
3+++ lib/lp/code/model/sourcepackagerecipebuild.py 2012-01-06 08:50:00 +0000
4@@ -290,8 +290,12 @@
5 def preloadBuildsData(cls, builds):
6 # Circular imports.
7 from lp.code.model.sourcepackagerecipe import SourcePackageRecipe
8+ from lp.services.librarian.model import LibraryFileAlias
9 package_builds = load_related(
10 PackageBuild, builds, ['package_build_id'])
11+ build_farm_jobs = [
12+ build.build_farm_job for build in builds]
13+ load_related(LibraryFileAlias, build_farm_jobs, ['log_id'])
14 archives = load_related(Archive, package_builds, ['archive_id'])
15 load_related(Person, archives, ['ownerID'])
16 sprs = load_related(
17
18=== modified file 'lib/lp/soyuz/browser/tests/test_builder.py'
19--- lib/lp/soyuz/browser/tests/test_builder.py 2012-01-02 11:21:14 +0000
20+++ lib/lp/soyuz/browser/tests/test_builder.py 2012-01-06 08:50:00 +0000
21@@ -100,7 +100,7 @@
22
23 self.assertThat(
24 recorder2,
25- HasQueryCount(LessThan(recorder1.count + 3 * 2 + 1)))
26+ HasQueryCount(LessThan(recorder1.count + 4 * 2 + 1)))
27
28 def test_builders_translation_template_build_query_count(self):
29 def create_build():
30
31=== modified file 'lib/lp/soyuz/browser/tests/test_builder_views.py'
32--- lib/lp/soyuz/browser/tests/test_builder_views.py 2012-01-06 08:50:00 +0000
33+++ lib/lp/soyuz/browser/tests/test_builder_views.py 2012-01-06 08:50:00 +0000
34@@ -15,7 +15,10 @@
35 from zope.component import getUtility
36 from zope.security.proxy import removeSecurityProxy
37
38-from lp.buildmaster.enums import BuildFarmJobType
39+from lp.buildmaster.enums import (
40+ BuildFarmJobType,
41+ BuildStatus,
42+ )
43 from lp.buildmaster.interfaces.buildfarmjob import (
44 IBuildFarmJobSource,
45 InconsistentBuildFarmJobError,
46@@ -159,6 +162,15 @@
47
48 class BuildCreationMixin(object):
49
50+ def markAsBuilt(self, build):
51+ lfa = self.factory.makeLibraryFileAlias()
52+ naked_build = removeSecurityProxy(build)
53+ naked_build.log = lfa
54+ naked_build.date_started = self.factory.getUniqueDate()
55+ naked_build.date_finished = self.factory.getUniqueDate()
56+ naked_build.status = BuildStatus.FULLYBUILT
57+ transaction.commit()
58+
59 def createTranslationTemplateBuildWithBuilder(self, builder=None):
60 if builder is None:
61 builder = self.factory.makeBuilder()
62@@ -169,7 +181,7 @@
63 branch = self.factory.makeBranch()
64 build = source.create(build_farm_job, branch)
65 removeSecurityProxy(build).builder = builder
66- self.addFakeBuildLog(build)
67+ self.markAsBuilt(build)
68 return build
69
70 def createRecipeBuildWithBuilder(self, private_branch=False,
71@@ -187,14 +199,9 @@
72 True, getUtility(IPersonSet).getByEmail(ADMIN_EMAIL))
73 Store.of(build).flush()
74 removeSecurityProxy(build).builder = builder
75- self.addFakeBuildLog(build)
76+ self.markAsBuilt(build)
77 return build
78
79- def addFakeBuildLog(self, build):
80- lfa = self.factory.makeLibraryFileAlias('mybuildlog.txt')
81- removeSecurityProxy(build).log = lfa
82- transaction.commit()
83-
84 def createBinaryPackageBuild(self, in_ppa=False, builder=None):
85 if builder is None:
86 builder = self.factory.makeBuilder()
87@@ -206,7 +213,7 @@
88 naked_build.builder = builder
89 naked_build.date_started = self.factory.getUniqueDate()
90 naked_build.date_finished = self.factory.getUniqueDate()
91- self.addFakeBuildLog(build)
92+ self.markAsBuilt(build)
93 return build
94
95
96
97=== modified file 'lib/lp/translations/model/translationtemplatesbuild.py'
98--- lib/lp/translations/model/translationtemplatesbuild.py 2012-01-01 02:58:52 +0000
99+++ lib/lp/translations/model/translationtemplatesbuild.py 2012-01-06 08:50:00 +0000
100@@ -1,4 +1,4 @@
101-# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
102+# Copyright 2010 Canonical Ltd. This software is licensed under the
103 # GNU Affero General Public License version 3 (see the file LICENSE).
104
105 """`TranslationTemplatesBuild` class."""
106@@ -117,21 +117,28 @@
107 """See `ITranslationTemplatesBuildSource`."""
108 store = cls._getStore(store)
109
110- def eager_load(rows):
111- # Load the related branches, products.
112- branches = load_related(
113- Branch, rows, ['branch_id'])
114- load_related(
115- Product, branches, ['productID'])
116- # Preload branches cached associated product series and
117- # suite source packages for all the related branches.
118- GenericBranchCollection.preloadDataForBranches(branches)
119-
120 resultset = store.find(
121 TranslationTemplatesBuild,
122 TranslationTemplatesBuild.build_farm_job_id.is_in(
123 buildfarmjob_ids))
124- return DecoratedResultSet(resultset, pre_iter_hook=eager_load)
125+ return DecoratedResultSet(
126+ resultset, pre_iter_hook=cls.preloadBuildsData)
127+
128+ @classmethod
129+ def preloadBuildsData(cls, builds):
130+ # Circular imports.
131+ from lp.services.librarian.model import LibraryFileAlias
132+ # Load the related branches, products.
133+ branches = load_related(
134+ Branch, builds, ['branch_id'])
135+ load_related(
136+ Product, branches, ['productID'])
137+ # Preload branches cached associated product series and
138+ # suite source packages for all the related branches.
139+ GenericBranchCollection.preloadDataForBranches(branches)
140+ build_farm_jobs = [
141+ build.build_farm_job for build in builds]
142+ load_related(LibraryFileAlias, build_farm_jobs, ['log_id'])
143
144 @classmethod
145 def findByBranch(cls, branch, store=None):