
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
... | ... | @@ -1037,4 +1037,14 @@ |
1037 | 1037 |
.findList(); |
1038 | 1038 |
} |
1039 | 1039 |
|
1040 |
+ public static int getNotificationsCount(User user) { |
|
1041 |
+ String sql = "select t1.id " + |
|
1042 |
+ "from n4user t0 " + |
|
1043 |
+ "left outer join notification_event_n4user t1z_ on t1z_.n4user_id = t0.id " + |
|
1044 |
+ "left outer join notification_event t1 on t1.id = t1z_.notification_event_id " + |
|
1045 |
+ "left outer join notification_mail t2 on t2.notification_event_id = t1.id " + |
|
1046 |
+ "where t0.id = " + user.id + " and t1.id IS NOT NULL "; |
|
1047 |
+ |
|
1048 |
+ return find.setRawSql(RawSqlBuilder.parse(sql).create()).findList().size(); |
|
1049 |
+ } |
|
1040 | 1050 |
} |
--- app/views/index/partial_notifications.scala.html
+++ app/views/index/partial_notifications.scala.html
... | ... | @@ -96,7 +96,7 @@ |
96 | 96 |
} |
97 | 97 |
} |
98 | 98 |
|
99 |
-@if(UserApp.currentUser.notificationEvents.size > size){ |
|
99 |
+@if(NotificationEvent.getNotificationsCount(UserApp.currentUser()) > size){ |
|
100 | 100 |
<li><a href="javascript: void(0);" id="notification-more" class="ybtn">More</a></li> |
101 | 101 |
<script type="text/javascript"> |
102 | 102 |
$(document).ready(function(){ |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?