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
 
@@ -2385,14 +2385,13 @@ class UserNotification(Base, BaseModel):
 
    user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True)
 
    notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True)
 
    read = Column('read', Boolean, default=False)
 
    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
 
        Session().add(self)
 

	
 

	
kallithea/model/notification.py
Show inline comments
 
@@ -28,12 +28,13 @@ Original author and date, and relevant c
 

	
 
import logging
 
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
 
from kallithea.model import BaseModel
 
from kallithea.model.db import Notification, User, UserNotification
 
from kallithea.model.meta import Session
 
@@ -164,13 +165,16 @@ class NotificationModel(BaseModel):
 
        """
 
        user = self._get_user(user)
 

	
 
        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_))
 

	
 
        return q.all()
 

	
0 comments (0 inline, 0 general)