~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/distroseries.py

[rs=buildbot-poller] automatic merge from stable. Revisions: 11265,
        11266, 11267 included.

Show diffs side-by-side

added added

removed removed

Lines of Context:
356
356
        # We join to SourcePackageName, ProductSeries, and Product to cache
357
357
        # the objects that are implcitly needed to work with a
358
358
        # Packaging object.
359
 
        # Avoid circular import failures.
360
359
        joins, conditions = self._current_sourcepackage_joins_and_conditions
361
 
        origin = SQL(joins + """
 
360
        # XXX: EdwinGrubbs 2010-07-29 bug=374777
 
361
        # Storm doesn't support DISTINCT ON.
 
362
        origin = SQL('''
 
363
            (
 
364
            SELECT DISTINCT ON (Packaging.id)
 
365
                Packaging.*,
 
366
                spr.component AS spr_component,
 
367
                SourcePackageName.name AS spn_name,
 
368
                total_bug_heat,
 
369
                po_messages
 
370
            FROM %(joins)s
 
371
            WHERE %(conditions)s
 
372
                AND packaging.id IS NOT NULL
 
373
            ) AS Packaging
362
374
            JOIN ProductSeries
363
375
                ON Packaging.productseries = ProductSeries.id
364
376
            JOIN Product
365
377
                ON ProductSeries.product = Product.id
366
 
            """)
367
 
        condition = SQL(conditions + "AND packaging.id IS NOT NULL")
368
 
        results = IStore(self).using(origin).find(Packaging, condition)
369
 
        return results.order_by("""
370
 
            (
371
 
                CASE WHEN spr.component = 1 THEN 1000 ELSE 0 END
 
378
            ''' % dict(joins=joins, conditions=conditions))
 
379
        return IStore(self).using(origin).find(Packaging).order_by('''
 
380
                (CASE WHEN spr_component = 1 THEN 1000 ELSE 0 END
372
381
                + CASE WHEN Product.bugtracker IS NULL
373
382
                    THEN coalesce(total_bug_heat, 10) ELSE 0 END
374
383
                + CASE WHEN ProductSeries.translations_autoimport_mode = 1
375
384
                    THEN coalesce(po_messages, 10) ELSE 0 END
376
 
                + CASE WHEN ProductSeries.branch IS NULL THEN 500
377
 
                    ELSE 0 END
378
 
            ) DESC,
379
 
            SourcePackageName.name ASC
380
 
            """)
 
385
                + CASE WHEN ProductSeries.branch IS NULL THEN 500 ELSE 0 END
 
386
                ) DESC,
 
387
                spn_name ASC
 
388
                ''')
381
389
 
382
390
    @property
383
391
    def _current_sourcepackage_joins_and_conditions(self):