Changeset - b91c5a6327bd
[Not reviewed]
default
0 1 0
Mads Kiilerich - 11 years ago 2015-01-06 00:54:36
madski@unity3d.com
comments: optimize notification creation

.append to the sqlalchemy collection is apparently expensive. Setting the
reference the other way around is much faster. Adding a notification for a
single user goes from 0.25 s to 0.001 s.

On a slow repo and a pullrequest with 14 reviewers, adding a comment goes from
8.5 s to 0.8 s.
1 file changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -2363,8 +2363,10 @@ class Notification(Base, BaseModel):
 
        for u in recipients:
 
            assoc = UserNotification()
 
            assoc.notification = notification
 
            u.notifications.append(assoc)
 
            assoc.user_id = u.user_id
 
            Session().add(assoc)
 
        Session().add(notification)
 
        Session().flush() # assign notificaiton.notification_id
 
        return notification
 

	
 
    @property
0 comments (0 inline, 0 general)