Mercurial > kallithea
changeset 4748:b91c5a6327bd
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.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Jan 2015 00:54:36 +0100 |
parents | 89bf1b081cc6 |
children | 3bf88f142f3d |
files | kallithea/model/db.py |
diffstat | 1 files changed, 3 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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