# HG changeset patch # User Mads Kiilerich # Date 1420502076 -3600 # Node ID 3bf88f142f3d81499330f5dd6477800822ee46d5 # Parent b91c5a6327bd0be6d39c9de5898b416e08fa7358 usernotifications: explicitly sort by date and join notifications and users - don't depend on lazy join diff -r b91c5a6327bd -r 3bf88f142f3d 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 @@ -2388,8 +2388,7 @@ sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None) user = relationship('User', lazy="joined") - notification = relationship('Notification', lazy="joined", - order_by=lambda: Notification.created_on.desc(),) + notification = relationship('Notification', lazy="joined") def mark_as_read(self): self.read = True diff -r b91c5a6327bd -r 3bf88f142f3d kallithea/model/notification.py --- a/kallithea/model/notification.py Tue Jan 06 00:54:36 2015 +0100 +++ b/kallithea/model/notification.py Tue Jan 06 00:54:36 2015 +0100 @@ -31,6 +31,7 @@ from pylons import tmpl_context as c from pylons.i18n.translation import _ +from sqlalchemy.orm import joinedload, subqueryload import kallithea from kallithea.lib import helpers as h @@ -167,7 +168,10 @@ q = UserNotification.query()\ .filter(UserNotification.user == user)\ .join((Notification, UserNotification.notification_id == - Notification.notification_id)) + Notification.notification_id))\ + .options(joinedload('notification'))\ + .options(subqueryload('notification.created_by_user'))\ + .order_by(Notification.created_on.desc()) if filter_: q = q.filter(Notification.type_.in_(filter_))