Commit 5c66f4be authored by Matija Obreza's avatar Matija Obreza
Browse files

Use ES for entry page counts


Signed-off-by: Matija Obreza's avatarMatija Obreza <matija.obreza@croptrust.org>
parent 41b04a60
......@@ -21,6 +21,7 @@ import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys.blocks.model.filters.DateFilter;
import org.genesys.catalog.service.DatasetService;
import org.genesys2.server.model.genesys.Accession;
......@@ -90,17 +91,30 @@ public class HtmlController extends BaseController {
@RequestMapping(value = "welcome")
public String welcome(ModelMap model) {
StopWatch stopWatch=new StopWatch();
stopWatch.start();
model.addAttribute("cropList", cropService.list(getLocale()));
printSplit("cropList", stopWatch);
model.addAttribute("lastNews", contentService.lastNews());
printSplit("lastNews", stopWatch);
model.addAttribute("welcomeBlurp", contentService.getGlobalArticle(ContentService.WELCOME, getLocale()));
printSplit("welcomeBlurp", stopWatch);
model.addAttribute("sideBlurp", contentService.getGlobalArticle(ContentService.SIDE_BLURP, getLocale()));
printSplit("sideBlurp", stopWatch);
model.addAttribute("organizationsBlurb", contentService.getGlobalArticle(ContentService.WELCOME_ORGANIZATIONS, getLocale()));
printSplit("organizationsBlurb", stopWatch);
model.addAttribute("numberOfCountries", statisticsService.numberOfCountries());
printSplit("numberOfCountries", stopWatch);
model.addAttribute("numberOfInstitutes", statisticsService.numberOfInstitutes());
printSplit("numberOfInstitutes", stopWatch);
model.addAttribute("numberOfAccessions", statisticsService.numberOfAccessions());
printSplit("numberOfAccessions", stopWatch);
model.addAttribute("numberOfActiveAccessions", statisticsService.numberOfActiveAccessions());
printSplit("numberOfActiveAccessions", stopWatch);
model.addAttribute("numberOfHistoricAccessions", statisticsService.numberOfHistoricAccessions());
printSplit("numberOfHistoricAccessions", stopWatch);
model.addAttribute("numberOfPublishedDatasets", statisticsService.numberOfPublishedDatasets());
printSplit("numberOfPublishedDatasets", stopWatch);
{
final Calendar date = Calendar.getInstance();
......@@ -110,14 +124,22 @@ public class HtmlController extends BaseController {
filter.lastModifiedDate = new DateFilter();
filter.lastModifiedDate.gt = date.getTime();
model.addAttribute("lastUpdatesOfInst", elasticsearchService.aggregateDate(5, FaoInstitute.class, Accession.class, "lastModifiedDate", "institute.id", filter));
printSplit("lastUpdatesOfInst", stopWatch);
}
model.addAttribute("lastDatasetsUpdates", datasetService.lastPublished());
printSplit("lastDatasetsUpdates", stopWatch);
model.addAttribute("organizations", organizationService.list(new PageRequest(0, 5)));
printSplit("organizations", stopWatch);
return "/index";
}
private void printSplit(String msg, StopWatch stopWatch) {
stopWatch.split();
LOG.debug("{}ms: {}", stopWatch.getSplitTime(), msg);
}
@RequestMapping(value = "login")
public String login() {
return "/login";
......
......@@ -18,7 +18,6 @@ package org.genesys2.server.service.filter;
import java.util.Set;
import java.util.UUID;
import org.genesys.blocks.model.filters.DateFilter;
import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter;
......@@ -93,9 +92,6 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
/** acce.lists uuid */
public Set<UUID> list;
/** The lastModifiedDate. */
public DateFilter lastModifiedDate;
/* (non-Javadoc)
* @see org.genesys.blocks.model.filters.BasicModelFilter#buildQuery()
......
......@@ -16,18 +16,20 @@
package org.genesys2.server.service.impl;
import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.service.DatasetService;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.genesys.PhenoStatistics;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.service.DatasetService;
import org.genesys2.server.persistence.PDCIRepository;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.StatisticsService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -35,8 +37,6 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional(readOnly = true)
public class StatisticsServiceImpl implements StatisticsService {
......@@ -52,10 +52,10 @@ public class StatisticsServiceImpl implements StatisticsService {
private GenesysService genesysService;
@Autowired
private DatasetService datasetService;
private ElasticsearchService elasticsearchService;
@Autowired
private PDCIRepository repoPdci;
@Autowired
private DatasetService datasetService;
@Override
@Cacheable(value = "statistics", key = "'stats.' + #root.methodName")
......@@ -70,21 +70,26 @@ public class StatisticsServiceImpl implements StatisticsService {
}
@Override
@Cacheable(value = "statistics", key = "'stats.' + #root.methodName")
// @Cacheable(value = "statistics", key = "'stats.' + #root.methodName")
public long numberOfAccessions() {
return genesysService.countAll();
AccessionFilter af = new AccessionFilter();
return elasticsearchService.count(Accession.class, af);
}
@Override
@Cacheable(value = "statistics", key = "'stats.' + #root.methodName")
// @Cacheable(value = "statistics", key = "'stats.' + #root.methodName")
public long numberOfActiveAccessions() {
return genesysService.countAllActive();
AccessionFilter af = new AccessionFilter();
af.historic = false;
return elasticsearchService.count(Accession.class, af);
}
@Override
@Cacheable(value = "statistics", key = "'stats.' + #root.methodName")
// @Cacheable(value = "statistics", key = "'stats.' + #root.methodName")
public long numberOfHistoricAccessions() {
return genesysService.countAllHistoric();
AccessionFilter af = new AccessionFilter();
af.historic = true;
return elasticsearchService.count(Accession.class, af);
}
@Override
......
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