Commit 11ff3298 authored by Matija Obreza's avatar Matija Obreza
Browse files

Cache countAccessions(filters)

parent 31b108a4
......@@ -30,6 +30,7 @@ import org.genesys2.server.service.impl.DirectMysqlQuery;
import org.genesys2.server.service.impl.DirectMysqlQuery.MethodResolver;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
......@@ -211,9 +212,10 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
}
@Override
public int countAccessions(final AppliedFilters filter) {
@Cacheable(value = "statistics", key = "'filtered-count-' + #filters")
public int countAccessions(final AppliedFilters filters) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.jsonFilter(filter, new MethodResolver() {
directQuery.jsonFilter(filters, new MethodResolver() {
@Override
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
......
......@@ -38,6 +38,7 @@ import org.genesys2.server.persistence.domain.TraitValueRepository;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
......@@ -65,6 +66,10 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
private static final Log LOG = LogFactory.getLog(GenesysFilterServiceImpl.class);
// using this loop to make @Cacheable work
@Autowired
private GenesysService genesysService;
@Autowired
private TraitValueRepository traitValueRepository;
......@@ -116,7 +121,8 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
});
directQuery.pageable(pageable);
final Long totalCount = this.jdbcTemplate.queryForObject(directQuery.getCountQuery("a.id"), directQuery.getParameters(), Long.class);
// Does this go through the cache?
final long totalCount = genesysService.countAccessions(filters);
LOG.info("Total count: " + totalCount);
if (totalCount > 0 && pageable.getPageNumber() * pageable.getPageSize() <= totalCount) {
......@@ -224,7 +230,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessiongeo", "geo");
directQuery.filterTile(zoom, xtile, ytile);
if (! filters.isEmpty()) {
if (!filters.isEmpty()) {
directQuery.innerJoin("accession", "a", "a.id=geo.accessionId");
directQuery.join(filters);
directQuery.filter(filters, new MethodResolver() {
......@@ -247,5 +253,6 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
return stmt;
}
}, rowHandler);
};
}
}
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