@@ -513,27 +513,47 @@ private void createCache(Repository repository, String sinceRevision) {
513
513
}
514
514
515
515
private void createCacheReal (Collection <Repository > repositories ) {
516
+ long start = System .currentTimeMillis ();
516
517
ExecutorService executor = RuntimeEnvironment .getHistoryExecutor ();
517
-
518
- final CountDownLatch latch = new CountDownLatch (repositories .size ());
518
+ // Since we know each repository object from the repositories
519
+ // collection is unique, we can abuse HashMap to create a list of
520
+ // repository,revision tuples with repository as key (as the revision
521
+ // string does not have to be unique - surely it is not unique
522
+ // for the initial index case).
523
+ HashMap <Repository ,String > repos2process = new HashMap <>();
524
+
525
+ // Collect the list of <latestRev,repo> pairs first so that we
526
+ // do not have to deal with latch decrementing in the cycle below.
519
527
for (final Repository repo : repositories ) {
520
528
final String latestRev ;
521
529
522
530
try {
523
531
latestRev = historyCache .getLatestCachedRevision (repo );
532
+ repos2process .put (repo , latestRev );
524
533
} catch (HistoryException he ) {
525
534
log .log (Level .WARNING ,
526
535
String .format (
527
536
"Failed to retrieve latest cached revision for %s" ,
528
537
repo .getDirectoryName ()), he );
529
- latch .countDown ();
530
- continue ;
531
538
}
539
+ }
540
+
541
+ log .log (Level .INFO , "Creating historycache for {0} repositories" ,
542
+ repos2process .size ());
543
+ final CountDownLatch latch = new CountDownLatch (repos2process .size ());
544
+ for (final Map .Entry <Repository ,String > entry : repos2process .entrySet ()) {
532
545
executor .submit (new Runnable () {
533
546
@ Override
534
547
public void run () {
535
- createCache (repo , latestRev );
536
- latch .countDown ();
548
+ try {
549
+ createCache (entry .getKey (), entry .getValue ());
550
+ } catch (Exception ex ) {
551
+ // We want to catch any exception since we are in thread.
552
+ log .log (Level .WARNING ,
553
+ "createCacheReal() got exception" + ex );
554
+ } finally {
555
+ latch .countDown ();
556
+ }
537
557
}
538
558
});
539
559
}
@@ -577,6 +597,10 @@ public void run() {
577
597
OpenGrokLogger .getLogger ().log (Level .WARNING ,
578
598
"Failed optimizing the history cache database" , he );
579
599
}
600
+ long stop = System .currentTimeMillis ();
601
+ String time_str = StringUtils .getReadableTime (stop - start );
602
+ log .log (Level .INFO , "Done historycache for all repositories (took {0})" ,
603
+ time_str );
580
604
}
581
605
582
606
public void createCache (Collection <String > repositories ) {
0 commit comments