From: James Moger Date: Mon, 8 Sep 2014 17:38:49 +0000 (-0400) Subject: Expose setting to control Lucene repository indexing frequency X-Git-Tag: v1.6.1~43^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Ftickets%2F61%2F161%2F1;p=gitblit.git Expose setting to control Lucene repository indexing frequency --- diff --git a/src/main/distrib/data/gitblit.properties b/src/main/distrib/data/gitblit.properties index f8d6c6d0..b975fc11 100644 --- a/src/main/distrib/data/gitblit.properties +++ b/src/main/distrib/data/gitblit.properties @@ -1006,6 +1006,12 @@ web.compressedDownloads = zip gz # SINCE 0.9.0 web.allowLuceneIndexing = true +# Control the frequency of Lucene repository indexing. +# The default setting is to check for updated refs every 2 mins. +# +# SINCE 1.6.1 +web.luceneFrequency = 2 mins + # Allows an authenticated user to create forks of a repository # # set this to false if you want to disable all fork controls on the web site diff --git a/src/main/java/com/gitblit/manager/RepositoryManager.java b/src/main/java/com/gitblit/manager/RepositoryManager.java index a8b23237..ac9ea156 100644 --- a/src/main/java/com/gitblit/manager/RepositoryManager.java +++ b/src/main/java/com/gitblit/manager/RepositoryManager.java @@ -1825,9 +1825,10 @@ public class RepositoryManager implements IRepositoryManager { protected void configureLuceneIndexing() { luceneExecutor = new LuceneService(settings, this); - int period = 2; - scheduledExecutor.scheduleAtFixedRate(luceneExecutor, 1, period, TimeUnit.MINUTES); - logger.info("Lucene will process indexed branches every {} minutes.", period); + String frequency = settings.getString(Keys.web.luceneFrequency, "2 mins"); + int mins = TimeUtils.convertFrequencyToMinutes(frequency, 2); + scheduledExecutor.scheduleAtFixedRate(luceneExecutor, 1, mins, TimeUnit.MINUTES); + logger.info("Lucene will process indexed branches every {} minutes.", mins); } protected void configureGarbageCollector() { @@ -1862,10 +1863,7 @@ public class RepositoryManager implements IRepositoryManager { protected void configureMirrorExecutor() { mirrorExecutor = new MirrorService(settings, this); if (mirrorExecutor.isReady()) { - int mins = TimeUtils.convertFrequencyToMinutes(settings.getString(Keys.git.mirrorPeriod, "30 mins")); - if (mins < 5) { - mins = 5; - } + int mins = TimeUtils.convertFrequencyToMinutes(settings.getString(Keys.git.mirrorPeriod, "30 mins"), 5); int delay = 1; scheduledExecutor.scheduleAtFixedRate(mirrorExecutor, delay, mins, TimeUnit.MINUTES); logger.info("Mirror service will fetch updates every {} minutes.", mins); diff --git a/src/main/java/com/gitblit/manager/ServicesManager.java b/src/main/java/com/gitblit/manager/ServicesManager.java index 37215786..437fd106 100644 --- a/src/main/java/com/gitblit/manager/ServicesManager.java +++ b/src/main/java/com/gitblit/manager/ServicesManager.java @@ -312,7 +312,7 @@ public class ServicesManager implements IManager { @Override public void reschedule(FederationModel registration) { // schedule the next pull - int mins = TimeUtils.convertFrequencyToMinutes(registration.frequency); + int mins = TimeUtils.convertFrequencyToMinutes(registration.frequency, 5); registration.nextPull = new Date(System.currentTimeMillis() + (mins * 60 * 1000L)); scheduledExecutor.schedule(new FederationPuller(registration), mins, TimeUnit.MINUTES); logger.info(MessageFormat.format( diff --git a/src/main/java/com/gitblit/servlet/FederationServlet.java b/src/main/java/com/gitblit/servlet/FederationServlet.java index 8dbf0e16..acbc0021 100644 --- a/src/main/java/com/gitblit/servlet/FederationServlet.java +++ b/src/main/java/com/gitblit/servlet/FederationServlet.java @@ -164,7 +164,7 @@ public class FederationServlet extends JsonServlet { // setup the last and netx pull dates results.lastPull = new Date(); - int mins = TimeUtils.convertFrequencyToMinutes(results.frequency); + int mins = TimeUtils.convertFrequencyToMinutes(results.frequency, 5); results.nextPull = new Date(System.currentTimeMillis() + (mins * 60 * 1000L)); // acknowledge the receipt of status diff --git a/src/main/java/com/gitblit/utils/TimeUtils.java b/src/main/java/com/gitblit/utils/TimeUtils.java index 4b113be2..c0e98e5d 100644 --- a/src/main/java/com/gitblit/utils/TimeUtils.java +++ b/src/main/java/com/gitblit/utils/TimeUtils.java @@ -322,12 +322,13 @@ public class TimeUtils { * Convert a frequency string into minutes. * * @param frequency + * @param minimumMins * @return minutes */ - public static int convertFrequencyToMinutes(String frequency) { + public static int convertFrequencyToMinutes(String frequency, int minimumMins) { // parse the frequency frequency = frequency.toLowerCase(); - int mins = 60; + int mins = minimumMins; if (!StringUtils.isEmpty(frequency)) { try { String str = frequency.trim(); @@ -337,16 +338,16 @@ public class TimeUtils { mins = (int) Float.parseFloat(str); } catch (NumberFormatException e) { } - if (mins < 5) { - mins = 5; + if (mins < minimumMins) { + mins = minimumMins; + } + if (frequency.indexOf("day") > -1) { + // convert to minutes + mins *= 1440; + } else if (frequency.indexOf("hour") > -1) { + // convert to minutes + mins *= 60; } - } - if (frequency.indexOf("day") > -1) { - // convert to minutes - mins *= 1440; - } else if (frequency.indexOf("hour") > -1) { - // convert to minutes - mins *= 60; } return mins; } diff --git a/src/test/java/com/gitblit/tests/TimeUtilsTest.java b/src/test/java/com/gitblit/tests/TimeUtilsTest.java index fb38ffd3..ef506ef4 100644 --- a/src/test/java/com/gitblit/tests/TimeUtilsTest.java +++ b/src/test/java/com/gitblit/tests/TimeUtilsTest.java @@ -100,9 +100,9 @@ public class TimeUtilsTest extends GitblitUnitTest { @Test public void testFrequency() { - assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins")); - assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins")); - assertEquals(600, TimeUtils.convertFrequencyToMinutes("10 hours")); - assertEquals(14400, TimeUtils.convertFrequencyToMinutes(" 10 days ")); + assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins", 5)); + assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins", 5)); + assertEquals(600, TimeUtils.convertFrequencyToMinutes("10 hours", 5)); + assertEquals(14400, TimeUtils.convertFrequencyToMinutes(" 10 days ", 5)); } }