Changeset - 3bf88f142f3d
[Not reviewed]
default
0 2 0
Mads Kiilerich - 11 years ago 2015-01-06 00:54:36
madski@unity3d.com
usernotifications: explicitly sort by date and join notifications and users - don't depend on lazy join
2 files changed with 6 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -2388,8 +2388,7 @@ class UserNotification(Base, BaseModel):
 
    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
kallithea/model/notification.py
Show inline comments
 
@@ -31,6 +31,7 @@ import traceback
 

	
 
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 @@ class NotificationModel(BaseModel):
 
        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_))
0 comments (0 inline, 0 general)