Merge lp:~lifeless/launchpad/bug-722794 into lp:launchpad

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 12648
Proposed branch: lp:~lifeless/launchpad/bug-722794
Merge into: lp:launchpad
Diff against target: 101 lines (+63/-9)
1 file modified
lib/lp/registry/model/distroseries.py (+63/-9)
To merge this branch: bzr merge lp:~lifeless/launchpad/bug-722794
Reviewer Review Type Date Requested Status
Steve Kowalik (community) Approve
Review via email: mp+54466@code.launchpad.net

Commit message

Use a tuned query plan for +needs-packaging

Description of the change

Hopefully solve a top-12 timeout using a query put together by stub. Does not alter the sister page +packaging which isn't currently timing out (perhaps due to unuse, or different stats leading to a different plan). I hope I've made why clear in the comments.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/distroseries.py'
2--- lib/lp/registry/model/distroseries.py 2011-03-22 04:40:12 +0000
3+++ lib/lp/registry/model/distroseries.py 2011-03-23 04:46:32 +0000
4@@ -474,21 +474,64 @@
5 translatable messages, and the source package release's component.
6 """
7 find_spec = (
8+ SQL("DISTINCT ON (score, sourcepackagename.name) TRUE as _ignored"),
9 SourcePackageName,
10 SQL("""
11 coalesce(total_bug_heat, 0) + coalesce(po_messages, 0) +
12- CASE WHEN spr.component = 1 THEN 1000 ELSE 0 END AS score"""),
13+ CASE WHEN component = 1 THEN 1000 ELSE 0 END AS score"""),
14 SQL("coalesce(bug_count, 0) AS bug_count"),
15 SQL("coalesce(total_messages, 0) AS total_messages"))
16- joins, conditions = self._current_sourcepackage_joins_and_conditions
17- origin = SQL(joins)
18- condition = SQL(conditions + "AND packaging.id IS NULL")
19+ # This does not use _current_sourcepackage_joins_and_conditions because
20+ # the two queries are working on different data sets - +needs-packaging
21+ # was timing out and +packaging wasn't, and destabilising things
22+ # unnecessarily is not good.
23+ origin = SQL("""
24+ SourcePackageName, (SELECT
25+ spr.sourcepackagename,
26+ spr.component,
27+ bug_count,
28+ total_bug_heat,
29+ SUM(POTemplate.messagecount) * %(po_message_weight)s AS po_messages,
30+ SUM(POTemplate.messagecount) AS total_messages
31+ FROM
32+ SourcePackageRelease AS spr
33+ JOIN SourcePackagePublishingHistory AS spph
34+ ON spr.id = spph.sourcepackagerelease
35+ JOIN Archive
36+ ON spph.archive = Archive.id
37+ JOIN Section
38+ ON spph.section = Section.id
39+ JOIN DistroSeries
40+ ON spph.distroseries = DistroSeries.id
41+ LEFT OUTER JOIN DistributionSourcePackage AS dsp
42+ ON dsp.sourcepackagename = spr.sourcepackagename
43+ AND dsp.distribution = DistroSeries.distribution
44+ LEFT OUTER JOIN POTemplate
45+ ON POTemplate.sourcepackagename = spr.sourcepackagename
46+ AND POTemplate.distroseries = DistroSeries.id
47+ WHERE
48+ DistroSeries.id = %(distroseries)s
49+ AND spph.status IN %(active_status)s
50+ AND Archive.purpose = %(primary)s
51+ AND Section.name <> 'translations'
52+ AND NOT EXISTS (
53+ SELECT TRUE FROM Packaging
54+ WHERE
55+ Packaging.sourcepackagename = spr.sourcepackagename
56+ AND Packaging.distroseries = spph.distroseries)
57+ GROUP BY
58+ spr.sourcepackagename, spr.component, bug_count, total_bug_heat
59+ ) AS spn_info""" % sqlvalues(
60+ po_message_weight=self._current_sourcepackage_po_weight,
61+ distroseries=self,
62+ active_status=active_publishing_status,
63+ primary=ArchivePurpose.PRIMARY))
64+ condition = SQL("""sourcepackagename.id = spn_info.sourcepackagename""")
65 results = IStore(self).using(origin).find(find_spec, condition)
66 results = results.order_by('score DESC', SourcePackageName.name)
67- results = results.config(distinct=True)
68
69- def decorator(result):
70- spn, score, bug_count, total_messages = result
71+ def decorator(row):
72+ _, spn, score, bug_count, total_messages = row
73 return {
74 'package': SourcePackage(
75 sourcepackagename=spn, distroseries=self),
76@@ -538,12 +581,23 @@
77 ''')
78
79 @property
80+ def _current_sourcepackage_po_weight(self):
81+ """See getPrioritized*."""
82+ # Bugs and PO messages are heuristically scored. These queries
83+ # can easily timeout so filters and weights are used to create
84+ # an acceptable prioritization of packages that is fast to excecute.
85+ return .5
86+
87+ @property
88 def _current_sourcepackage_joins_and_conditions(self):
89- """The SQL joins and conditions to prioritize source packages."""
90+ """The SQL joins and conditions to prioritize source packages.
91+
92+ Used for getPrioritizedPackagings only.
93+ """
94 # Bugs and PO messages are heuristically scored. These queries
95 # can easily timeout so filters and weights are used to create
96 # an acceptable prioritization of packages that is fast to excecute.
97- po_message_weight = .5
98+ po_message_weight = self._current_sourcepackage_po_weight
99 message_score = ("""
100 LEFT JOIN (
101 SELECT