Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -re0cf9de846687ea2189b663ec9f593abd246e7ff -r4f7ee8239da980f9bdb403845dfff1aa2e39ed64 Binary files differ Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java =================================================================== diff -u -r2e5d858e9dd95ddc9aa092c307b2039c9cb62930 -r4f7ee8239da980f9bdb403845dfff1aa2e39ed64 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java (.../ILearnerProgressDAO.java) (revision 2e5d858e9dd95ddc9aa092c307b2039c9cb62930) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java (.../ILearnerProgressDAO.java) (revision 4f7ee8239da980f9bdb403845dfff1aa2e39ed64) @@ -24,6 +24,7 @@ package org.lamsfoundation.lams.lesson.dao; import java.util.List; +import java.util.Map; import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.lesson.LearnerProgress; @@ -186,7 +187,7 @@ Integer getNumUsersCompletedLesson(Long lessonId); /** - * Get number of learners who are at the given activity at the moment. + * Get number of learners who are at the given activities at the moment. */ - Integer getNumUsersCurrentActivity(Activity activity); -} + Map getNumUsersCurrentActivities(Long[] activityIds); +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java =================================================================== diff -u -r2e5d858e9dd95ddc9aa092c307b2039c9cb62930 -r4f7ee8239da980f9bdb403845dfff1aa2e39ed64 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java (.../LearnerProgressDAO.java) (revision 2e5d858e9dd95ddc9aa092c307b2039c9cb62930) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java (.../LearnerProgressDAO.java) (revision 4f7ee8239da980f9bdb403845dfff1aa2e39ed64) @@ -24,6 +24,8 @@ package org.lamsfoundation.lams.lesson.dao.hibernate; import java.util.List; +import java.util.Map; +import java.util.TreeMap; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -65,15 +67,15 @@ + " where p.lessonComplete > 0 and p.lesson.id = :lessonId"; private final static String COUNT_ATTEMPTED_ACTIVITY = "select count(*) from LearnerProgress prog, " - + " Activity act join prog.attemptedActivities attAct " + " where act.id = :activityId and " + + " Activity act join prog.attemptedActivities attAct where act.id = :activityId and " + " index(attAct) = act"; private final static String COUNT_COMPLETED_ACTIVITY = "select count(*) from LearnerProgress prog, " - + " Activity act join prog.completedActivities compAct " + " where act.id = :activityId and " + + " Activity act join prog.completedActivities compAct where act.id = :activityId and " + " index(compAct) = act"; - private final static String COUNT_CURRENT_ACTIVITY = "select count(*) from LearnerProgress prog WHERE " - + " prog.currentActivity = :activity"; + private final static String COUNT_CURRENT_ACTIVITY = "select prog.currentActivity.activityId, count(prog) " + + "from LearnerProgress prog WHERE prog.currentActivity.activityId IN (:activityIds) GROUP BY prog.currentActivity.activityId"; private final static String LOAD_PROGRESS_BY_LESSON = "from LearnerProgress p " + " where p.lesson.id = :lessonId order by p.user.lastName, p.user.firstName, p.user.userId"; @@ -308,10 +310,23 @@ return ((Number) value).intValue(); } + @SuppressWarnings("unchecked") @Override - public Integer getNumUsersCurrentActivity(Activity activity) { - Object value = getSession().createQuery(LearnerProgressDAO.COUNT_CURRENT_ACTIVITY) - .setEntity("activity", activity).uniqueResult(); - return ((Number) value).intValue(); + public Map getNumUsersCurrentActivities(Long[] activityIds) { + List resultQuery = getSession().createQuery(LearnerProgressDAO.COUNT_CURRENT_ACTIVITY) + .setParameterList("activityIds", activityIds).list(); + Map result = new TreeMap(); + // put all requested activity IDs into the result + for (Long activityId : activityIds) { + result.put(activityId, 0); + } + // update only the existing ones + for (Object[] entry : resultQuery) { + // for some reason entry can be null + if (entry != null) { + result.put((Long) entry[0], ((Long) entry[1]).intValue()); + } + } + return result; } } \ No newline at end of file Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java =================================================================== diff -u -r708bd4d049ae0a59d70c964ef2f864d2b7a352e6 -r4f7ee8239da980f9bdb403845dfff1aa2e39ed64 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 708bd4d049ae0a59d70c964ef2f864d2b7a352e6) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 4f7ee8239da980f9bdb403845dfff1aa2e39ed64) @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.SortedSet; import org.lamsfoundation.lams.learningdesign.Activity; @@ -345,7 +346,7 @@ void removeLesson(long lessonId, Integer userId) throws SecurityException; /** - * Removes the lesson and all referenced resources (learning design, tool content etc.) from the database. + * Removes the lesson and all referenced resources (learning design, tool content etc.) from the database. */ void removeLessonPermanently(long lessonId, Integer userId) throws SecurityException; @@ -674,13 +675,13 @@ * Activity id of the branchingActivity */ SortedSet getGroupsNotAssignedToBranch(Long branchingActivityID) throws LessonServiceException; - + /** * Get all the users records where the user has attempted the given activity, but has not completed it yet. Uses the * progress records to determine the users. */ List getLearnersAttemptedActivity(Activity activity); - + /** * give the users in all tool sessions for an activity (if it is a tool activity) or it will give all the users who * have attempted an activity that doesn't have any tool sessions, i.e. system activities such as branching. @@ -718,9 +719,9 @@ Integer getCountLearnersFromProgress(Long lessonId, String searchPhrase); /** - * Get number of learners who are at the given activity at the moment. + * Get number of learners who are at the given activities at the moment. */ - Integer getCountLearnersCurrentActivity(Activity activity); + Map getCountLearnersCurrentActivities(Long[] activityIds); /** * Get number of learners who finished the given lesson. Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r708bd4d049ae0a59d70c964ef2f864d2b7a352e6 -r4f7ee8239da980f9bdb403845dfff1aa2e39ed64 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 708bd4d049ae0a59d70c964ef2f864d2b7a352e6) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 4f7ee8239da980f9bdb403845dfff1aa2e39ed64) @@ -2410,10 +2410,10 @@ } @Override - public List getLearnersAttemptedActivity(Activity activity){ + public List getLearnersAttemptedActivity(Activity activity) { return learnerProgressDAO.getLearnersAttemptedActivity(activity); } - + @Override public List getLearnersAttemptedOrCompletedActivity(Activity activity) throws LessonServiceException { return lessonService.getLearnersAttemptedOrCompletedActivity(activity); @@ -2452,8 +2452,8 @@ } @Override - public Integer getCountLearnersCurrentActivity(Activity activity) { - return learnerProgressDAO.getNumUsersCurrentActivity(activity); + public Map getCountLearnersCurrentActivities(Long[] activityIds) { + return learnerProgressDAO.getNumUsersCurrentActivities(activityIds); } @Override Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java =================================================================== diff -u -r708bd4d049ae0a59d70c964ef2f864d2b7a352e6 -r4f7ee8239da980f9bdb403845dfff1aa2e39ed64 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 708bd4d049ae0a59d70c964ef2f864d2b7a352e6) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 4f7ee8239da980f9bdb403845dfff1aa2e39ed64) @@ -131,7 +131,6 @@ // --------------------------------------------------------------------- // Class level constants - Struts forward // --------------------------------------------------------------------- - private static final String PREVIEW_DELETED_REPORT_SCREEN = "previewdeleted"; private static final String NOT_SUPPORTED_SCREEN = "notsupported"; private static final String TIME_CHART_SCREEN = "timeChart"; private static final String ERROR = "error"; @@ -815,8 +814,8 @@ for (User learner : learners) { learnersJSON.put(WebUtil.userToJSON(learner)); } - - learnerCount = getMonitoringService().getCountLearnersCurrentActivity(activity); + learnerCount = getMonitoringService().getCountLearnersCurrentActivities(new Long[] { activityId }) + .get(activityId); } JSONObject responseJSON = new JSONObject(); @@ -1101,7 +1100,6 @@ JSONObject responseJSON = new JSONObject(); Lesson lesson = getLessonService().getLesson(lessonId); LearningDesign learningDesign = lesson.getLearningDesign(); - String contentFolderId = learningDesign.getContentFolderID(); Locale userLocale = new Locale(user.getLocaleLanguage(), user.getLocaleCountry()); @@ -1221,6 +1219,14 @@ responseJSON.put("searchedLearnerFound", searchedLearnerProgress != null); } + // Fetch number of learners at each activity + Long[] activityIds = new Long[activities.size()]; + int index = 0; + for (Activity activity : activities) { + activityIds[index++] = activity.getActivityId(); + } + Map learnerCounts = getMonitoringService().getCountLearnersCurrentActivities(activityIds); + JSONArray activitiesJSON = new JSONArray(); for (Activity activity : activities) { Long activityId = activity.getActivityId(); @@ -1266,25 +1272,18 @@ } // find few latest users and count of all users for each activity - int learnerCount = 0; + int learnerCount = learnerCounts.get(activityId); if (activity.isBranchingActivity() || activity.isOptionsWithSequencesActivity()) { // go through hidden children of complex activities and take them into account - learnerCount += getMonitoringService().getCountLearnersCurrentActivity(activity); Set children = parentToChildren.get(activityId); if (children != null) { for (Activity child : children) { - learnerCount += getMonitoringService().getCountLearnersCurrentActivity(child); + learnerCount += learnerCounts.get(child.getActivityId()); } } } else { List latestLearners = getMonitoringService().getLearnersLatestByActivity(activity.getActivityId(), MonitoringAction.LATEST_LEARNER_PROGRESS_ACTIVITY_DISPLAY_LIMIT, null); - if (latestLearners.size() < MonitoringAction.LATEST_LEARNER_PROGRESS_ACTIVITY_DISPLAY_LIMIT) { - // if there are less learners than the limit, we already know the size - learnerCount = latestLearners.size(); - } else { - learnerCount = getMonitoringService().getCountLearnersCurrentActivity(activity); - } if ((searchedLearnerProgress != null) && (searchedLearnerProgress.getCurrentActivity() != null) && activity.getActivityId()