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
 
@@ -58,13 +58,13 @@ class NotificationsController(BaseContro
 
        super(NotificationsController, self).__before__()
 

	
 
    def index(self, format='html'):
 
        """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)
 
        c.notifications = Page(notif, page=p, items_per_page=10)
 
        c.pull_request_type = Notification.TYPE_PULL_REQUEST
 
        c.comment_type = [Notification.TYPE_CHANGESET_COMMENT,
kallithea/model/notification.py
Show inline comments
 
@@ -163,13 +163,13 @@ class NotificationModel(BaseModel):
 
                Session().delete(obj)
 
                return True
 
        except Exception:
 
            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
 

	
 
        :param user:
 
        :param filter:
 
        """
 
@@ -183,13 +183,13 @@ class NotificationModel(BaseModel):
 
            .options(subqueryload('notification.created_by_user')) \
 
            .order_by(Notification.created_on.desc())
 

	
 
        if filter_:
 
            q = q.filter(Notification.type_.in_(filter_))
 

	
 
        return q.all()
 
        return q
 

	
 
    def mark_read(self, user, notification):
 
        try:
 
            notification = self.__get_notification(notification)
 
            user = self._get_user(user)
 
            if notification and user:
0 comments (0 inline, 0 general)