changeset 5963:85bb68f64597

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.
author Konstantin Veretennicov <kveretennicov@gmail.com>
date Thu, 09 Jun 2016 20:41:44 +0200
parents 2ffd56ea2629
children 5e501b6ee639
files kallithea/controllers/admin/notifications.py kallithea/model/notification.py
diffstat 2 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/notifications.py	Fri Jun 10 01:19:58 2016 +0200
+++ b/kallithea/controllers/admin/notifications.py	Thu Jun 09 20:41:44 2016 +0200
@@ -61,7 +61,7 @@
         """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)
--- a/kallithea/model/notification.py	Fri Jun 10 01:19:58 2016 +0200
+++ b/kallithea/model/notification.py	Thu Jun 09 20:41:44 2016 +0200
@@ -166,7 +166,7 @@
             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 @@
         if filter_:
             q = q.filter(Notification.type_.in_(filter_))
 
-        return q.all()
+        return q
 
     def mark_read(self, user, notification):
         try: