Skip to content

Commit 5d4d725

Browse files
committed
[TLC-1172] Paginate CrisMetric db rows when updating index
1 parent 69c9e43 commit 5d4d725

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

dspace-api/src/main/java/org/dspace/metrics/UpdateCrisMetricsInSolrDocService.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.dspace.discovery.IndexingService;
2222
import org.dspace.discovery.SearchServiceException;
2323
import org.dspace.scripts.handler.DSpaceRunnableHandler;
24+
import org.dspace.services.ConfigurationService;
2425
import org.dspace.utils.DSpace;
2526

2627
/**
@@ -30,6 +31,8 @@ public class UpdateCrisMetricsInSolrDocService {
3031

3132
private static final Logger log = LogManager.getLogger(UpdateCrisMetricsInSolrDocService.class);
3233

34+
private ConfigurationService configurationService = new DSpace().getConfigurationService();
35+
3336
private CrisMetricsService crisMetricsService = new DSpace().getServiceManager().getServiceByName(
3437
CrisMetricsServiceImpl.class.getName(), CrisMetricsServiceImpl.class);
3538

@@ -42,21 +45,28 @@ public void performUpdate(Context context, DSpaceRunnableHandler handler, boolea
4245

4346
public void performUpdate(Context context, DSpaceRunnableHandler handler, boolean optimize, UUID resourceUuid) {
4447
try {
45-
List<CrisMetrics> metrics = resourceUuid == null
46-
? crisMetricsService.findAllLast(context,-1,-1)
47-
: crisMetricsService.findLastMetricsByResourceId(context, resourceUuid, -1, -1);
48+
int offset = 0;
49+
int limit = configurationService.getIntProperty("metrics.indexer.page", 1000);
4850
handler.logInfo("Metric update start");
49-
for (CrisMetrics metric : metrics) {
50-
try {
51-
crisIndexingService.updateMetrics(context, metric);
52-
} catch (RemoteSolrException rse) {
53-
if (StringUtils.containsIgnoreCase(rse.getMessage(), "Did not find child ID Item-")) {
54-
log.error(rse.getMessage());
55-
} else {
56-
throw rse;
51+
List<CrisMetrics> metrics;
52+
while (!(metrics = (resourceUuid == null
53+
? crisMetricsService.findAllLast(context, limit, offset)
54+
: crisMetricsService.findLastMetricsByResourceId(context, resourceUuid, limit, offset)
55+
)).isEmpty()) {
56+
for (CrisMetrics metric : metrics) {
57+
try {
58+
crisIndexingService.updateMetrics(context, metric);
59+
} catch (RemoteSolrException rse) {
60+
if (StringUtils.containsIgnoreCase(rse.getMessage(), "Did not find child ID Item-")) {
61+
log.error(rse.getMessage());
62+
} else {
63+
throw rse;
64+
}
5765
}
5866
}
67+
offset += limit;
5968
}
69+
6070
handler.logInfo("Metric update end");
6171
if (optimize) {
6272
handler.logInfo("Starting solr optimization");
@@ -68,4 +78,4 @@ public void performUpdate(Context context, DSpaceRunnableHandler handler, boolea
6878
throw new RuntimeException(e.getMessage(), e);
6979
}
7080
}
71-
}
81+
}

dspace/config/modules/metrics.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ metrics.scopus.person.instToken = ${scopus.instToken}
2525
# The default limit for the items to be updated by the update-metrics script, used if no limit is provided as parameter
2626
metrics.update-metrics-script.limit = 1750
2727

28+
# The page size of CrisMetrics rows to process when updating the solr index
29+
# Default: 1000
30+
metrics.indexer.page = 1000
31+
2832
#---------------------------------------------------------------#
2933
# Configure altmetric.com badges. #
3034
# See http://api.altmetric.com/embeds.html #
@@ -131,4 +135,4 @@ plumx.list-data-hide-mentions = false
131135
plumx.list-data-hide-socialmedia = false
132136
plumx.list-data-hide-citations = false
133137
plumx.list-data-pass-hidden-categories = false
134-
plumx.list-data-detail-same-page = false
138+
plumx.list-data-detail-same-page = false

0 commit comments

Comments
 (0)