FIX: Cache exist query results

This commit is contained in:
Roland Praml
2021-08-27 13:56:51 +02:00
committed by Jonas Pöhler
parent 56fed3ad87
commit 83f8435000
4 changed files with 50 additions and 1 deletions
@@ -81,6 +81,11 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
*/
ID_LIST(FIND_ID_LIST, "findIds"),
/**
* Find exists.
*/
EXISTS(FIND_EXISTS, "exists"),
/**
* Find single attribute.
*/
@@ -26,6 +26,7 @@ public interface TxnProfileEventCodes {
String FIND_MANY = "fm";
String FIND_ITERATE = "fe";
String FIND_ID_LIST = "fi";
String FIND_EXISTS = "ex";
String FIND_ATTRIBUTE = "fa";
String FIND_COUNT = "fc";
String FIND_SUBQUERY = "fs";
@@ -1291,7 +1291,12 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
@Override
public <T> boolean exists(Query<T> ormQuery, Transaction transaction) {
Query<T> ormQueryCopy = ormQuery.copy().setMaxRows(1);
SpiOrmQueryRequest<?> request = createQueryRequest(Type.ID_LIST, ormQueryCopy, transaction);
SpiOrmQueryRequest<?> request = createQueryRequest(Type.EXISTS, ormQueryCopy, transaction);
List<Object> ids = request.getFromQueryCache();
if (ids != null) {
return !ids.isEmpty();
}
try {
request.initTransIfRequired();
return !request.findIds().isEmpty();