# HG changeset patch # User Konstantin Veretennicov # Date 2016-06-09 20:41:44 # Node ID 85bb68f64597cadc7c0225b0a349cba978a36a76 # Parent 2ffd56ea26299ef1bb7be4e9eb10df65337fdd69 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. diff --git a/kallithea/controllers/admin/notifications.py b/kallithea/controllers/admin/notifications.py --- a/kallithea/controllers/admin/notifications.py +++ b/kallithea/controllers/admin/notifications.py @@ -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) diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py --- a/kallithea/model/notification.py +++ b/kallithea/model/notification.py @@ -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: