~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/archivesubscriber.py

  • Committer: Danilo Segan
  • Date: 2011-08-12 15:58:16 UTC
  • mto: This revision was merged to the branch mainline in revision 13691.
  • Revision ID: danilo@canonical.com-20110812155816-gvwivss2xk051cng
Make getNonActiveSubscribers return preferred email addresses as well to cut down on the individual queries for each of them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
from canonical.database.constants import UTC_NOW
32
32
from canonical.database.enumcol import DBEnum
 
33
from canonical.launchpad.database.emailaddress import EmailAddress
 
34
from canonical.launchpad.interfaces.emailaddress import EmailAddressStatus
33
35
from lp.registry.interfaces.person import validate_person
34
36
from lp.registry.model.teammembership import TeamParticipation
35
37
from lp.soyuz.interfaces.archiveauthtoken import IArchiveAuthTokenSet
108
110
                TeamParticipation,
109
111
                TeamParticipation.personID == Person.id)
110
112
 
 
113
            # Only return people with preferred email address set.
 
114
            preferred_email = Join(
 
115
                EmailAddress, EmailAddress.personID == Person.id)
 
116
 
111
117
            # We want to get all participants who are themselves
112
118
            # individuals, not teams:
113
119
            non_active_subscribers = store.using(
114
 
                Person, team_participation, auth_token).find(
115
 
                Person,
 
120
                Person, team_participation, preferred_email, auth_token).find(
 
121
                (Person, EmailAddress),
 
122
                EmailAddress.status == EmailAddressStatus.PREFERRED,
116
123
                TeamParticipation.teamID == self.subscriber_id,
117
124
                Person.teamowner == None,
 
125
                # There is no existing archive auth token.
118
126
                ArchiveAuthToken.person_id == None)
119
127
            non_active_subscribers.order_by(Person.name)
120
128
            return non_active_subscribers
128
136
                return EmptyResultSet()
129
137
 
130
138
            # Otherwise return a result set containing only the
131
 
            # subscriber.
132
 
            return store.find(Person, Person.id == self.subscriber_id)
 
139
            # subscriber and their preferred email address.
 
140
            return store.find(
 
141
                (Person, EmailAddress),
 
142
                Person.id == self.subscriber_id,
 
143
                EmailAddress.personID == Person.id,
 
144
                EmailAddress.status == EmailAddressStatus.PREFERRED)
133
145
 
134
146
 
135
147
class ArchiveSubscriberSet: