MNT-20775 : deleted-nodes with maxitems parameter take longer (#255)

* MNT-20775 : rest api /deleted-nodes with maxitems parameter take longer when there are more items in the trash can
  Based on offset and limit, returns only the required results from database
  Added count query for ArchivedNodes
This commit is contained in:
Alexandru-Eusebiu Epure
2021-01-27 17:15:34 +02:00
committed by GitHub
parent 3d0099d742
commit 14ca5bb726
3 changed files with 45 additions and 5 deletions

View File

@@ -113,7 +113,7 @@ public abstract class AbstractCannedQuery<R> implements CannedQuery<R>
final List<List<R>> finalPages = pages;
// Has more items beyond requested pages ? ... ie. at least one more page (with at least one result)
final boolean hasMoreItems = (rawResults.size() > pagingDetails.getResultsRequiredForPaging());
final boolean hasMoreItems = (rawResults.size() > pagingDetails.getResultsRequiredForPaging()) || (totalCount.getFirst() > pagingDetails.getResultsRequiredForPaging());
results = new CannedQueryResults<R>()
{

View File

@@ -36,6 +36,7 @@ import org.alfresco.repo.domain.query.CannedQueryDAO;
import org.alfresco.repo.security.permissions.impl.acegi.AbstractCannedQueryPermissions;
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityBean;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -51,6 +52,7 @@ public class GetArchivedNodesCannedQuery extends AbstractCannedQueryPermissions<
private static final String QUERY_NAMESPACE = "alfresco.query.archivednodes";
private static final String QUERY_SELECT_GET_ARCHIVED_NODES = "select_GetArchivedNodesCannedQuery";
private static final String QUERY_SELECT_COUNT_ARCHIVED_NODES = "select_CountAllArchivedNodes";
private CannedQueryDAO cannedQueryDAO;
private NodeDAO nodeDAO;
@@ -81,12 +83,12 @@ public class GetArchivedNodesCannedQuery extends AbstractCannedQueryPermissions<
return Collections.emptyList();
}
int resultsRequired = parameters.getResultsRequired();
paramBean.setLimit(resultsRequired);
int offset = parameters.getPageDetails().getSkipResults();
int limit = parameters.getPageDetails().getPageSize();
// note: refer to SQL for specific DB filtering and sorting
List<ArchivedNodeEntity> results = cannedQueryDAO.executeQuery(QUERY_NAMESPACE,
QUERY_SELECT_GET_ARCHIVED_NODES, paramBean, 0, Integer.MAX_VALUE);
QUERY_SELECT_GET_ARCHIVED_NODES, paramBean, offset, limit);
List<NodeRef> nodeRefs = new ArrayList<NodeRef>(results.size());
for (ArchivedNodeEntity entity : results)
@@ -119,4 +121,38 @@ public class GetArchivedNodesCannedQuery extends AbstractCannedQueryPermissions<
+ (System.currentTimeMillis() - start) + " msecs");
}
}
@Override
protected Pair<Integer, Integer> getTotalResultCount(List<ArchivedNodeEntity> results)
{
Object paramBeanObj = super.getParameters().getParameterBean();
if (paramBeanObj == null)
{
throw new NullPointerException(
"Required parameters not provided for GetArchivedNodes canned query, unexpected null value for query params");
}
GetArchivedNodesCannedQueryParams paramBean = (GetArchivedNodesCannedQueryParams) paramBeanObj;
if (paramBean.getParentNodeId() == null)
{
throw new NullPointerException(
"Required parameters not provided for GetArchivedNodes canned queryUnexpected null value for parentNodeId");
}
Long totalResultCountLongValue = cannedQueryDAO.executeCountQuery(QUERY_NAMESPACE, QUERY_SELECT_COUNT_ARCHIVED_NODES, paramBean);
int totalResultCount = totalResultCountLongValue.intValue();
if (totalResultCount < 0)
{
totalResultCount = Integer.MAX_VALUE;
}
return new Pair<>(totalResultCount, totalResultCount);
}
@Override
protected boolean isApplyPostQueryPaging()
{
return false;
}
}

View File

@@ -10,4 +10,8 @@
<include refid="alfresco.node.select_GetAllArchivedNodesCannedQuery"/>
<if test="limit != 0">limit ${limit}</if>
</select>
<select id="select_CountAllArchivedNodes" parameterType="ArchivedNodes" resultType="long">
select count(id) from alf_child_assoc where parent_node_id = #{parentNodeId} and type_qname_id = #{assocTypeQNameId}
</select>
</mapper>