2121import org .dspace .discovery .IndexingService ;
2222import org .dspace .discovery .SearchServiceException ;
2323import org .dspace .scripts .handler .DSpaceRunnableHandler ;
24+ import org .dspace .services .ConfigurationService ;
2425import 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+ }
0 commit comments