~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/bugnotification.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
        # Now we do some calls that are purely for cacheing.
145
145
        # Converting these into lists forces the queries to execute.
146
146
        if pending_notifications:
147
 
            cached_people = list(
 
147
            list(
148
148
                getUtility(IPersonSet).getPrecachedPersonsFromIDs(
149
149
                    list(people_ids),
150
150
                    need_validity=True,
151
151
                    need_preferred_email=True))
152
 
            cached_bugs = list(
 
152
            list(
153
153
                IStore(Bug).find(Bug, In(Bug.id, list(bug_ids))))
154
154
        pending_notifications.reverse()
155
155
        return pending_notifications
189
189
 
190
190
        return bug_notification
191
191
 
192
 
    def getRecipientFilterData(self, recipient_to_sources, notifications):
 
192
    def getRecipientFilterData(self, bug, recipient_to_sources,
 
193
                               notifications):
193
194
        """See `IBugNotificationSet`."""
194
195
        if not notifications or not recipient_to_sources:
195
196
            # This is a shortcut that will remove some error conditions.
196
197
            return {}
 
198
        # Collect bug mute information.
 
199
        from lp.bugs.model.bug import BugMute
 
200
        store = IStore(BugMute)
 
201
        muted_person_ids = set(list(
 
202
            store.find(BugMute.person_id,
 
203
                       BugMute.bug == bug)))
197
204
        # This makes two calls to the database to get all the
198
205
        # information we need. The first call gets the filter ids and
199
206
        # descriptions for each recipient, and then we divide up the
202
209
        source_person_id_map = {}
203
210
        recipient_id_map = {}
204
211
        for recipient, sources in recipient_to_sources.items():
 
212
            if recipient.id in muted_person_ids:
 
213
                continue
205
214
            source_person_ids = set()
206
215
            recipient_id_map[recipient.id] = {
207
216
                'principal': recipient,
231
240
            Join(StructuralSubscription,
232
241
                 BugSubscriptionFilter.structural_subscription_id ==
233
242
                    StructuralSubscription.id))
234
 
        filter_data = source.find(
235
 
            (StructuralSubscription.subscriberID,
236
 
             BugSubscriptionFilter.id,
237
 
             BugSubscriptionFilter.description),
238
 
            In(BugNotificationFilter.bug_notification_id,
239
 
               [notification.id for notification in notifications]),
240
 
            In(StructuralSubscription.subscriberID,
241
 
               source_person_id_map.keys()))
 
243
        if len(source_person_id_map) == 0:
 
244
            filter_data = []
 
245
        else:
 
246
            filter_data = source.find(
 
247
                (StructuralSubscription.subscriberID,
 
248
                 BugSubscriptionFilter.id,
 
249
                 BugSubscriptionFilter.description),
 
250
                In(BugNotificationFilter.bug_notification_id,
 
251
                   [notification.id for notification in notifications]),
 
252
                In(StructuralSubscription.subscriberID,
 
253
                   source_person_id_map.keys()))
242
254
        filter_ids = []
243
255
        # Record the filters for each source.
244
256
        for source_person_id, filter_id, filter_description in filter_data:
259
271
            mute_data = store.find(
260
272
                (BugSubscriptionFilterMute.person_id,
261
273
                 BugSubscriptionFilterMute.filter_id),
262
 
                In(BugSubscriptionFilterMute.person_id, recipient_id_map.keys()),
 
274
                In(BugSubscriptionFilterMute.person_id,
 
275
                   recipient_id_map.keys()),
263
276
                In(BugSubscriptionFilterMute.filter_id, filter_ids))
264
277
            for person_id, filter_id in mute_data:
265
278
                if filter_id in recipient_id_map[person_id]['filters']: