# HG changeset patch # User Mads Kiilerich # Date 1420502076 -3600 # Node ID b91c5a6327bd0be6d39c9de5898b416e08fa7358 # Parent 89bf1b081cc6449a7b9c0eb5c7b7f1864a0f22b0 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. diff -r 89bf1b081cc6 -r b91c5a6327bd kallithea/model/db.py --- a/kallithea/model/db.py Tue Jan 06 00:54:36 2015 +0100 +++ b/kallithea/model/db.py Tue Jan 06 00:54:36 2015 +0100 @@ -2363,8 +2363,10 @@ 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