Commit 688ec119 authored by Michael Ritter's avatar Michael Ritter
Browse files

Separate queries for all summaries and group summary

parent 2154c5b8
...@@ -21,27 +21,35 @@ public class GroupSummaryContext implements ServletContextListener { ...@@ -21,27 +21,35 @@ public class GroupSummaryContext implements ServletContextListener {
public static Map<String, GroupSummary> summaries; public static Map<String, GroupSummary> summaries;
// Main query /**
private static final String SUMMARY_QUERY = "SELECT c.colgroup, sum(m.size) AS size, sum(m.count) AS count " + * Query to get ALL group summaries
*/
private static final String SUMMARY_QUERY_ALL = "SELECT c.colgroup, sum(m.size) AS size, sum(m.count) AS count " +
"FROM collection c " + "FROM collection c " +
"JOIN ( " + "JOIN ( " +
"SELECT sum(size) AS size, count(id) AS count, parentcollection_id " + "SELECT sum(size) AS size, count(id) AS count, parentcollection_id " +
"FROM monitored_item " + "FROM monitored_item " +
"WHERE directory = 0 " + "WHERE directory = 0 " +
"GROUP BY parentcollection_id " + "GROUP BY parentcollection_id " +
") AS m ON c.id = m.parentcollection_id "; ") AS m ON c.id = m.parentcollection_id " +
"WHERE c.colgroup IS NOT NULL " +
// clauses depending on if we're querying on a group or not "GROUP BY c.colgroup";
private static final String SUMMARY_QUERY_NOT_NULL = "WHERE c.colgroup IS NOT NULL ";
private static final String SUMMARY_QUERY_PARAM = "WHERE c.colgroup = ? ";
// and the wrap up /**
private static final String SUMMARY_QUERY_END = "GROUP BY c.colgroup"; * Query to get the group summary for a single group
*/
private static final String SUMMARY_QUERY_GROUP = "select c.colgroup, sum(m.size) AS size, count(m.id) AS count " +
"FROM monitored_item m " +
"JOIN ( " +
" select colgroup, id " +
" FROM collection " +
" WHERE colgroup = ? " +
") c ON c.id = m.parentcollection_id WHERE directory = 0";
@Override @Override
public void contextInitialized(ServletContextEvent servletContextEvent) { public void contextInitialized(ServletContextEvent servletContextEvent) {
summaries = new HashMap<>(); summaries = new HashMap<>();
updateSummaries(ImmutableList.of(SUMMARY_QUERY, SUMMARY_QUERY_NOT_NULL, SUMMARY_QUERY_END), updateSummaries(ImmutableList.of(SUMMARY_QUERY_ALL),
ImmutableList.<String>of()); ImmutableList.<String>of());
} }
...@@ -55,11 +63,12 @@ public class GroupSummaryContext implements ServletContextListener { ...@@ -55,11 +63,12 @@ public class GroupSummaryContext implements ServletContextListener {
* *
* @param group the group to update * @param group the group to update
*/ */
@SuppressWarnings("WeakerAccess")
public static void updateGroup(String group) { public static void updateGroup(String group) {
if (group != null) { if (group != null) {
log.debug("Updating group summary for " + group); log.debug("Updating group summary for " + group);
updateSummaries( updateSummaries(
ImmutableList.of(SUMMARY_QUERY, SUMMARY_QUERY_PARAM, SUMMARY_QUERY_END), ImmutableList.of(SUMMARY_QUERY_GROUP),
ImmutableList.of(group)); ImmutableList.of(group));
} }
} }
...@@ -87,6 +96,7 @@ public class GroupSummaryContext implements ServletContextListener { ...@@ -87,6 +96,7 @@ public class GroupSummaryContext implements ServletContextListener {
List<GroupSummary> results = (List<GroupSummary>)groupSummary.getResultList(); List<GroupSummary> results = (List<GroupSummary>)groupSummary.getResultList();
for (GroupSummary result : results) { for (GroupSummary result : results) {
log.info("Result: group " + result.getGroup() + ", size: " + result.getSize() + ", count: " + result.getCount());
summaries.put(result.getGroup(), result); summaries.put(result.getGroup(), result);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment