[ SEARCH-2181 ] Use MaxResults in NodeMetaDataParameters

This commit is contained in:
agazzarini
2020-04-14 14:23:34 +02:00
parent c639ffcf9b
commit 4b901e5846
3 changed files with 52 additions and 43 deletions
@@ -144,7 +144,6 @@ import org.alfresco.solr.content.SolrContentStore;
import org.alfresco.solr.logging.Log;
import org.alfresco.solr.tracker.IndexHealthReport;
import org.alfresco.solr.tracker.TrackerStats;
import org.alfresco.solr.utils.Utils;
import org.alfresco.util.ISO9075;
import org.alfresco.util.Pair;
import org.apache.commons.io.input.BoundedInputStream;
@@ -1514,7 +1513,8 @@ public class SolrInformationServer implements InformationServer
}
else
{
nodeMetaDatas = nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE);
nmdp.setMaxResults(Integer.MAX_VALUE);
nodeMetaDatas = getNodesMetaDataFromRepository(nmdp);
}
NodeMetaData nodeMetaData;
@@ -1558,8 +1558,8 @@ public class SolrInformationServer implements InformationServer
NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
nmdp.setFromNodeId(node.getId());
nmdp.setToNodeId(node.getId());
Collection<NodeMetaData> nodeMetaDatas = nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE);
nmdp.setMaxResults(Integer.MAX_VALUE);
Collection<NodeMetaData> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp);
AddUpdateCommand addDocCmd = new AddUpdateCommand(request);
addDocCmd.overwrite = overwrite;
@@ -1723,8 +1723,9 @@ public class SolrInformationServer implements InformationServer
nmdp.setIncludePaths(true);
nmdp.setIncludeProperties(false);
nmdp.setIncludeTxnId(true);
nmdp.setMaxResults(1);
// Gets only one
Collection<NodeMetaData> nodeMetaDatas = nodesMetaDataFromRepository(nmdp, 1);
Collection<NodeMetaData> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp);
allNodeMetaDatas.addAll(nodeMetaDatas);
}
@@ -1867,7 +1868,8 @@ public class SolrInformationServer implements InformationServer
nmdp.setIncludeAspects(false);
nmdp.setIncludePaths(false);
nmdp.setIncludeParentAssociations(false);
nodeMetaDatas.addAll(nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE));
nmdp.setMaxResults(Integer.MAX_VALUE);
nodeMetaDatas.addAll(getNodesMetaDataFromRepository(nmdp));
}
for (NodeMetaData nodeMetaData : nodeMetaDatas)
@@ -1912,7 +1914,8 @@ public class SolrInformationServer implements InformationServer
nmdp.setIncludeChildAssociations(false);
// Fetches bulk metadata
Collection<NodeMetaData> nodeMetaDatas = nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE);
nmdp.setMaxResults(Integer.MAX_VALUE);
Collection<NodeMetaData> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp);
NEXT_NODE:
for (NodeMetaData nodeMetaData : nodeMetaDatas)
@@ -2489,7 +2492,8 @@ public class SolrInformationServer implements InformationServer
NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
nmdp.setFromNodeId(dbId);
nmdp.setToNodeId(dbId);
Collection<NodeMetaData> nodeMetaDatas = nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE);
nmdp.setMaxResults(Integer.MAX_VALUE);
Collection<NodeMetaData> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp);
SolrInputDocument newDoc = null;
if (!nodeMetaDatas.isEmpty())
{
@@ -3380,8 +3384,9 @@ public class SolrInformationServer implements InformationServer
nmdp.setIncludeProperties(false);
nmdp.setIncludeType(false);
nmdp.setIncludeTxnId(true);
nmdp.setMaxResults(1);
// Gets only one
Collection<NodeMetaData> nodeMetaDatas = nodesMetaDataFromRepository(nmdp, 1);
Collection<NodeMetaData> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp);
if (!nodeMetaDatas.isEmpty())
{
@@ -3829,11 +3834,11 @@ public class SolrInformationServer implements InformationServer
solrContentStore.flushChangeSet();
}
private Collection<NodeMetaData> nodesMetaDataFromRepository(NodeMetaDataParameters parameters, int maxResults)
private Collection<NodeMetaData> getNodesMetaDataFromRepository(NodeMetaDataParameters parameters)
{
try
{
return notNullOrEmpty(repositoryClient.getNodesMetaData(parameters, maxResults));
return notNullOrEmpty(repositoryClient.getNodesMetaData(parameters));
}
catch (JSONException exception)
{
@@ -3842,7 +3847,7 @@ public class SolrInformationServer implements InformationServer
}
catch (Exception exception)
{
LOGGER.error("Unable to get nodes metadata from repository. See the stacktrace below for further details.");
LOGGER.error("Unable to get nodes metadata from repository. See the stacktrace below for further details.", exception);
return Collections.emptyList();
}
}
@@ -1,31 +1,32 @@
/*
* #%L
* Alfresco Solr Client
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* #%L
* Alfresco Solr Client
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.solr.client;
import java.util.List;
import java.util.OptionalInt;
/**
* Stores node meta data query parameters for use in SOLR remote api calls
@@ -39,7 +40,7 @@ public class NodeMetaDataParameters
private Long toTxnId;
// default is 'all' results
private int maxResults = 0;
private OptionalInt maxResults = OptionalInt.empty();
private Long fromNodeId;
private Long toNodeId;
@@ -147,14 +148,14 @@ public class NodeMetaDataParameters
this.includeParentAssociations = includeParentAssociations;
}
public int getMaxResults()
public OptionalInt getMaxResults()
{
return maxResults;
}
public void setMaxResults(int maxResults)
{
this.maxResults = maxResults;
this.maxResults = OptionalInt.of(maxResults);
}
public List<Long> getNodeIds()
@@ -732,7 +732,7 @@ public class SOLRAPIClient
return ret;
}
public List<NodeMetaData> getNodesMetaData(NodeMetaDataParameters params, int maxResults) throws AuthenticationException, IOException, JSONException
public List<NodeMetaData> getNodesMetaData(NodeMetaDataParameters params) throws AuthenticationException, IOException, JSONException
{
List<Long> nodeIds = params.getNodeIds();
@@ -801,13 +801,16 @@ public class SOLRAPIClient
body.put("includeTxnId", params.isIncludeTxnId());
}
body.put("maxResults", maxResults);
if (params.getMaxResults().isPresent())
{
body.put("maxResults", params.getMaxResults());
}
PostRequest req = new PostRequest(url.toString(), body.toString(), "application/json");
JSONObject json = callRepository(GET_METADATA_URL, req);
JSONArray jsonNodes = json.getJSONArray("nodes");
List<NodeMetaData> nodes = new ArrayList<NodeMetaData>(jsonNodes.length());
List<NodeMetaData> nodes = new ArrayList<>(jsonNodes.length());
for(int i = 0; i < jsonNodes.length(); i++)
{
JSONObject jsonNodeInfo = jsonNodes.getJSONObject(i);