# HG changeset patch # User Mads Kiilerich # Date 2015-01-06 00:54:36 # 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 --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -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