Skip to content

Commit c7b4642

Browse files
committed
implement tunable for suppressing history fetch other than from the cache
fixes #446
1 parent 89935a2 commit c7b4642

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,16 @@ public void setChattyStatusPage(boolean chatty) {
887887
threadConfig.get().setChattyStatusPage(chatty);
888888
}
889889

890+
public boolean noFetchHistoryWhenNotInCache() {
891+
String enabled =
892+
System.getProperty("org.opensolaris.opengrok.history.noFetchWhenNotInCache");
893+
if (enabled != null) {
894+
return true;
895+
}
896+
897+
return (false);
898+
}
899+
890900
/**
891901
* Read an configuration file and set it as the current configuration.
892902
*

src/org/opensolaris/opengrok/history/FileHistoryCache.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ class FileHistoryCache implements HistoryCache {
6363
private final Object lock = new Object();
6464
private String historyCacheDirName = "historycache";
6565
private String latestRevFileName = "OpenGroklatestRev";
66+
private boolean historyIndexDone = false;
67+
68+
@Override
69+
public void setHistoryIndexDone() {
70+
historyIndexDone = true;
71+
}
72+
73+
@Override
74+
public boolean isHistoryIndexDone() {
75+
return historyIndexDone;
76+
}
6677

6778
/**
6879
* Generate history for single file.
@@ -445,6 +456,13 @@ public History get(File file, Repository repository, boolean withFiles)
445456
}
446457
}
447458

459+
// Some repository checkouts may contain lots of files untracked by
460+
// given SCM. For these it would be waste of time to get their history.
461+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
462+
if (isHistoryIndexDone() && env.noFetchHistoryWhenNotInCache()) {
463+
return null;
464+
}
465+
448466
final History history;
449467
long time;
450468
try {
@@ -464,7 +482,6 @@ public History get(File file, Repository repository, boolean withFiles)
464482
// a sub-directory change. This will cause us to present a stale
465483
// history log until a the current directory is updated and
466484
// invalidates the cache entry.
467-
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
468485
if ((cache != null) &&
469486
(cache.exists() ||
470487
(time > env.getHistoryReaderTimeLimit()))) {

src/org/opensolaris/opengrok/history/HistoryCache.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.history;
2424

@@ -27,7 +27,6 @@
2727
import java.util.Map;
2828

2929
interface HistoryCache {
30-
3130
/**
3231
* Create and initialize an empty history cache if one doesn't exist
3332
* already.
@@ -133,4 +132,8 @@ Map<String, Date> getLastModifiedTimes(
133132
* @throws HistoryException if an error occurred while getting the info
134133
*/
135134
String getInfo() throws HistoryException;
135+
136+
// Set and query if history index phase is done.
137+
void setHistoryIndexDone();
138+
boolean isHistoryIndexDone();
136139
}

src/org/opensolaris/opengrok/history/HistoryGuru.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.history;
2424

@@ -162,8 +162,7 @@ public Annotation annotate(File file, String rev) throws IOException {
162162
}
163163

164164
/**
165-
* Get the appropriate history reader for the file specified by parent and
166-
* basename.
165+
* Get the appropriate history reader for given file.
167166
*
168167
* @param file The file to get the history reader for
169168
* @throws HistoryException If an error occurs while getting the history
@@ -601,6 +600,7 @@ public void run() {
601600
String time_str = StringUtils.getReadableTime(stop - start);
602601
log.log(Level.INFO, "Done historycache for all repositories (took {0})",
603602
time_str);
603+
historyCache.setHistoryIndexDone();
604604
}
605605

606606
public void createCache(Collection<String> repositories) {

src/org/opensolaris/opengrok/history/JDBCHistoryCache.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757

5858
class JDBCHistoryCache implements HistoryCache {
5959

60+
private boolean historyIndexDone = false;
61+
6062
/** The schema in which the tables live. */
6163
private static final String SCHEMA = "OPENGROK";
6264

@@ -1384,4 +1386,14 @@ private void doRenamedHistory(final Repository repository, File file,
13841386
}
13851387
}
13861388
}
1389+
1390+
@Override
1391+
public void setHistoryIndexDone() {
1392+
historyIndexDone = true;
1393+
}
1394+
1395+
@Override
1396+
public boolean isHistoryIndexDone() {
1397+
return historyIndexDone;
1398+
}
13871399
}

0 commit comments

Comments
 (0)