mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-17 14:21:39 +00:00
* 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
(cherry picked from commit 14ca5bb726
)
This commit is contained in:
committed by
GitHub
parent
62ee57bb51
commit
6f6136f9da
@@ -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>()
|
||||
{
|
||||
|
@@ -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;
|
||||
@@ -75,18 +77,18 @@ public class GetArchivedNodesCannedQuery extends AbstractCannedQueryPermissions<
|
||||
|
||||
// Get parameters
|
||||
GetArchivedNodesCannedQueryParams paramBean = (GetArchivedNodesCannedQueryParams) paramBeanObj;
|
||||
|
||||
|
||||
if (paramBean.getParentNodeId() == null || paramBean.getParentNodeId() < 0)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -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>
|
Reference in New Issue
Block a user