Changeset - cf1d1239cd55
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 7 years ago 2018-11-28 21:22:28
thomas.de_schampheleire@nokia.com
model: notification: don't round-trip via list if you want a set

'create' in NotificationModel starts from an empty list, appends entries to
it, then converts it to a set.
You could equally start with a set and add to it, avoiding the final
conversion.
1 file changed with 2 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/model/notification.py
Show inline comments
 
@@ -65,22 +65,21 @@ class NotificationModel(object):
 
        email_kwargs = email_kwargs or {}
 
        if recipients and not getattr(recipients, '__iter__', False):
 
            raise Exception('recipients must be a list or iterable')
 

	
 
        created_by_obj = User.guess_instance(created_by)
 

	
 
        recipients_objs = []
 
        recipients_objs = set()
 
        if recipients:
 
            for u in recipients:
 
                obj = User.guess_instance(u)
 
                if obj is not None:
 
                    recipients_objs.append(obj)
 
                    recipients_objs.add(obj)
 
                else:
 
                    # TODO: inform user that requested operation couldn't be completed
 
                    log.error('cannot email unknown user %r', u)
 
            recipients_objs = set(recipients_objs)
 
            log.debug('sending notifications %s to %s',
 
                type_, recipients_objs
 
            )
 
        elif recipients is None:
 
            # empty recipients means to all admins
 
            recipients_objs = User.query().filter(User.admin == True).all()
0 comments (0 inline, 0 general)