~wgrant/launchpad/specworkload

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2012-10-15 06:41:16 UTC
  • Revision ID: william.grant@canonical.com-20121015064116-kxuk47sidyqi543y
Rewrite Person.specifications query to be a bit more performant.

Show diffs side-by-side

added added

removed removed

Lines of Context:
885
885
        # in this case the "base" is quite complicated because it is
886
886
        # determined by the roles so lets do that first
887
887
 
888
 
        role_filter = []
 
888
        main_role_filter = []
889
889
        if SpecificationFilter.CREATOR in filter:
890
 
            role_filter.append(Specification.owner == self)
 
890
            main_role_filter.append(Specification.owner == self)
891
891
        if SpecificationFilter.ASSIGNEE in filter:
892
 
            role_filter.append(Specification.assignee == self)
 
892
            main_role_filter.append(Specification.assignee == self)
893
893
        if SpecificationFilter.DRAFTER in filter:
894
 
            role_filter.append(Specification.drafter == self)
 
894
            main_role_filter.append(Specification.drafter == self)
895
895
        if SpecificationFilter.APPROVER in filter:
896
 
            role_filter.append(Specification.approver == self)
 
896
            main_role_filter.append(Specification.approver == self)
 
897
        role_filtered_ids = Select(
 
898
            Specification.id, tables=[Specification],
 
899
            where=Or(*main_role_filter))
 
900
 
897
901
        if SpecificationFilter.SUBSCRIBER in filter:
898
 
            role_filter.append(
899
 
                Specification.id.is_in(
900
 
                    Select(
901
 
                        SpecificationSubscription.specificationID,
902
 
                        tables=[SpecificationSubscription],
903
 
                        where=(SpecificationSubscription.person == self))))
 
902
            role_filtered_ids = Union(
 
903
                role_filtered_ids,
 
904
                Select(
 
905
                    SpecificationSubscription.specificationID,
 
906
                    tables=[SpecificationSubscription],
 
907
                    where=(SpecificationSubscription.person == self)),
 
908
                all=True)
904
909
 
905
910
        # filter out specs on inactive products
906
 
        filters = [Or(*role_filter)]
 
911
        filters = [Specification.id.is_in(role_filtered_ids)]
907
912
        filters.append(
908
913
            Or(
909
914
                Specification.product == None,
910
 
                Not(Specification.productID.is_in(
911
 
                    Select(
912
 
                        Product.id, tables=[Product],
913
 
                        where=(Product.active == False))))))
 
915
                Exists(Select(
 
916
                    1, tables=[Product],
 
917
                    where=And(
 
918
                        Product.active,
 
919
                        Product.id == Specification.productID)))))
914
920
 
915
921
        if SpecificationFilter.ALL not in filter:
916
922
            # look for informational specs