Changeset - 85bb68f64597
[Not reviewed]
default
0 2 0
Konstantin Veretennicov - 9 years ago 2016-06-09 20:41:44
kveretennicov@gmail.com
notifications: improve response time when number of notifications is large

NotificationsController always retrieved materialized list of all notifications
in database, even to display only 10 of them. This is improved by feeding
SQLAlchemy Query object directly to webhelpers.paginate.Page, avoiding eager
load of all notifications.
2 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/notifications.py
Show inline comments
 
@@ -61,7 +61,7 @@ class NotificationsController(BaseContro
 
        """GET /_admin/notifications: All items in the collection"""
 
        # url('notifications')
 
        c.user = self.authuser
 
        notif = NotificationModel().get_for_user(self.authuser.user_id,
 
        notif = NotificationModel().query_for_user(self.authuser.user_id,
 
                                            filter_=request.GET.getall('type'))
 

	
 
        p = safe_int(request.GET.get('page', 1), 1)
kallithea/model/notification.py
Show inline comments
 
@@ -166,7 +166,7 @@ class NotificationModel(BaseModel):
 
            log.error(traceback.format_exc())
 
            raise
 

	
 
    def get_for_user(self, user, filter_=None):
 
    def query_for_user(self, user, filter_=None):
 
        """
 
        Get notifications for given user, filter them if filter dict is given
 

	
 
@@ -186,7 +186,7 @@ class NotificationModel(BaseModel):
 
        if filter_:
 
            q = q.filter(Notification.type_.in_(filter_))
 

	
 
        return q.all()
 
        return q
 

	
 
    def mark_read(self, user, notification):
 
        try:
0 comments (0 inline, 0 general)