#1061 - findCount query is not cached in L2 query cache

This commit is contained in:
rob bygrave
2017-07-06 21:51:52 +12:00
parent 95aed6af54
commit 166bcd7c45
5 changed files with 38 additions and 3 deletions
@@ -1300,6 +1300,10 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
public <T> int findCountWithCopy(Query<T> query, Transaction t) {
SpiOrmQueryRequest<T> request = createQueryRequest(Type.COUNT, query, t);
Integer result = request.getFromQueryCache();
if (result != null) {
return result;
}
try {
request.initTransIfRequired();
return request.findCount();
@@ -546,7 +546,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements BeanQueryRe
* </p>
*/
public boolean isAuditReads() {
return !query.isDisableReadAudit() && beanDescriptor.isReadAuditing();
return beanDescriptor.isReadAuditing() && !query.isDisableReadAudit();
}
/**
@@ -117,7 +117,7 @@ public interface SpiOrmQueryRequest<T> extends DocQueryRequest<T> {
/**
* Try to get the query result from the query cache.
*/
Object getFromQueryCache();
<A> A getFromQueryCache();
/**
* Return the Database platform like clause.
@@ -70,7 +70,11 @@ public class DefaultOrmQueryEngine implements OrmQueryEngine {
public <T> int findCount(OrmQueryRequest<T> request) {
flushJdbcBatchOnQuery(request);
return queryEngine.findCount(request);
int result = queryEngine.findCount(request);
if (request.getQuery().isUseQueryCache()) {
request.putToQueryCache(result);
}
return result;
}
@Override
+27
View File
@@ -4,6 +4,7 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.bean.BeanCollection;
import io.ebean.cache.ServerCache;
import org.ebeantest.LoggedSqlCollector;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import org.tests.model.cache.EColAB;
@@ -84,6 +85,32 @@ public class TestQueryCache extends BaseTestCase {
assertThat(colA_Second).isNotSameAs(colA_NotDistinct);
}
@Test
public void findCount() {
new EColAB("04", "count").save();
new EColAB("05", "count").save();
LoggedSqlCollector.start();
int count0 = Ebean.find(EColAB.class)
.setUseQueryCache(true)
.where()
.eq("columnB", "count")
.findCount();
int count1 = Ebean.find(EColAB.class)
.setUseQueryCache(true)
.where()
.eq("columnB", "count")
.findCount();
List<String> sql = LoggedSqlCollector.stop();
assertThat(count0).isEqualTo(count1);
assertThat(sql).hasSize(1);
}
@Test
@SuppressWarnings("unchecked")
public void test() {