diff --git a/app/models/NotificationEvent.java b/app/models/NotificationEvent.java index 257d49c4b..970c826de 100644 --- a/app/models/NotificationEvent.java +++ b/app/models/NotificationEvent.java @@ -20,6 +20,8 @@ */ package models; +import com.avaje.ebean.RawSql; +import com.avaje.ebean.RawSqlBuilder; import controllers.UserApp; import controllers.routes; import models.enumeration.*; @@ -1020,12 +1022,29 @@ public static void onStart() { * @return */ public static List findByReceiver(User user, int from, int size) { - List allEvents = user.notificationEvents; - int allEventsCount = allEvents.size(); - if (allEventsCount <= from) { - return new ArrayList<>(); - } - int to = (allEventsCount < from + size) ? allEventsCount : from + size; - return allEvents.subList(from, to); + String sql = "select t1.id, t1.title, t1.sender_id, t1.created, t1.resource_type, t1.resource_id, t1.event_type, " + + "t1.old_value, t1.new_value " + + "from n4user t0 " + + "left outer join notification_event_n4user t1z_ on t1z_.n4user_id = t0.id " + + "left outer join notification_event t1 on t1.id = t1z_.notification_event_id " + + "left outer join notification_mail t2 on t2.notification_event_id = t1.id " + + "where t0.id = " + user.id + " and t1.id IS NOT NULL " + + "order by t1.created DESC"; + + return find.setRawSql(RawSqlBuilder.parse(sql).create()) + .setFirstRow(from) + .setMaxRows(size) + .findList(); + } + + public static int getNotificationsCount(User user) { + String sql = "select t1.id " + + "from n4user t0 " + + "left outer join notification_event_n4user t1z_ on t1z_.n4user_id = t0.id " + + "left outer join notification_event t1 on t1.id = t1z_.notification_event_id " + + "left outer join notification_mail t2 on t2.notification_event_id = t1.id " + + "where t0.id = " + user.id + " and t1.id IS NOT NULL "; + + return find.setRawSql(RawSqlBuilder.parse(sql).create()).findList().size(); } } diff --git a/app/views/index/partial_notifications.scala.html b/app/views/index/partial_notifications.scala.html index 1075831ae..dafe49c59 100644 --- a/app/views/index/partial_notifications.scala.html +++ b/app/views/index/partial_notifications.scala.html @@ -96,7 +96,7 @@ } } -@if(UserApp.currentUser.notificationEvents.size > size){ +@if(NotificationEvent.getNotificationsCount(UserApp.currentUser()) > size){
  • More