Keesun Baik 2015-01-26
Enhanced performance for counting notifications
Problem
* So many columns are used when counting notifications.

Solution
* Fixed to use only one column by using raw sql for counting notifications,
and it reduces the fist page's loading time.
@6aee0073ab0cd7dee7e74789c784be37e4ba5b75
app/models/NotificationEvent.java
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
@@ -1037,4 +1037,14 @@
                 .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();
+    }
 }
app/views/index/partial_notifications.scala.html
--- app/views/index/partial_notifications.scala.html
+++ app/views/index/partial_notifications.scala.html
@@ -96,7 +96,7 @@
     }
 }
 
-@if(UserApp.currentUser.notificationEvents.size > size){
+@if(NotificationEvent.getNotificationsCount(UserApp.currentUser()) > size){
 <li><a href="javascript: void(0);" id="notification-more" class="ybtn">More</a></li>
 <script type="text/javascript">
     $(document).ready(function(){
Add a comment
List