Alfresco / alfresco-community-repo

Community Content Service Repository
https://www.alfresco.com/it/ecm-software/alfresco-community-edition
GNU Lesser General Public License v3.0
134 stars 81 forks source link

ReST API Search: Fix override of pagination when providing a limits parameter #2908

Open AFaust opened 5 days ago

AFaust commented 5 days ago

This PR addresses a bug found by a customer yesterday in which the pagination object in a search query payload was effectively ignored when a limits object was provided. Since the repository contained millions of documents, this cause a larger than expected amount of nodes to be loaded after the SOLR query was complete, causing an unexpected memory peak and potential out-of-memory error.

The following is the type of query that caused the problem:

{
    "query": {
        "query": "<...query...>"
    },
    "paging": {
        "maxItems": 1000,
        "skipCount": 0
    },
    "limits": {
        "permissionEvaluationTime": 200000,
        "permissionEvaluationCount": 200000
    }
}

The reason for increasing the permission evaluation count + time is to deal with the fact that a user may not have access to a lot of the low level results, requiring a larger limit to fill the expected maxItems for the pagination.

Expected behaviour: Search executed and returns either 1000 (matching) items or fewer when the permission check limits have been reached Observed behaviour: Search executed and might return many more results than specified via maxItems or causing an out-of-memory error in the repository