]> source.dussan.org Git - gitblit.git/commitdiff
Expose setting to control Lucene repository indexing frequency 61/161/1
authorJames Moger <james.moger@gitblit.com>
Mon, 8 Sep 2014 17:38:49 +0000 (13:38 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 8 Sep 2014 17:40:22 +0000 (13:40 -0400)
src/main/distrib/data/gitblit.properties
src/main/java/com/gitblit/manager/RepositoryManager.java
src/main/java/com/gitblit/manager/ServicesManager.java
src/main/java/com/gitblit/servlet/FederationServlet.java
src/main/java/com/gitblit/utils/TimeUtils.java
src/test/java/com/gitblit/tests/TimeUtilsTest.java

index f8d6c6d05024d8bffa558b6758c0f83eb72603b3..b975fc11429b4eb3475f369aa11243e90882422c 100644 (file)
@@ -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
index a8b23237354faf35d646ff034a0e690692c3afec..ac9ea156155430a128ed4f221b63bf3ec799e66f 100644 (file)
@@ -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);
index 37215786a91df4ae5b3f5728b89a3dab82abf8f4..437fd1068d70698f31043eacaeb809c440b002ed 100644 (file)
@@ -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(
index 8dbf0e1674045c2b50efa805879daeab4dd7ad5f..acbc00213a41ec7715bb1624bdf686de36c5517d 100644 (file)
@@ -164,7 +164,7 @@ public class FederationServlet extends JsonServlet {
 \r
                        // setup the last and netx pull dates\r
                        results.lastPull = new Date();\r
-                       int mins = TimeUtils.convertFrequencyToMinutes(results.frequency);\r
+                       int mins = TimeUtils.convertFrequencyToMinutes(results.frequency, 5);\r
                        results.nextPull = new Date(System.currentTimeMillis() + (mins * 60 * 1000L));\r
 \r
                        // acknowledge the receipt of status\r
index 4b113be208665352f51cf44e31617568cdc16e50..c0e98e5d325223fec567bb9904a46f29808164b4 100644 (file)
@@ -322,12 +322,13 @@ public class TimeUtils {
         * Convert a frequency string into minutes.\r
         *\r
         * @param frequency\r
+        * @param minimumMins\r
         * @return minutes\r
         */\r
-       public static int convertFrequencyToMinutes(String frequency) {\r
+       public static int convertFrequencyToMinutes(String frequency, int minimumMins) {\r
                // parse the frequency\r
                frequency = frequency.toLowerCase();\r
-               int mins = 60;\r
+               int mins = minimumMins;\r
                if (!StringUtils.isEmpty(frequency)) {\r
                        try {\r
                                String str = frequency.trim();\r
@@ -337,16 +338,16 @@ public class TimeUtils {
                                mins = (int) Float.parseFloat(str);\r
                        } catch (NumberFormatException e) {\r
                        }\r
-                       if (mins < 5) {\r
-                               mins = 5;\r
+                       if (mins < minimumMins) {\r
+                               mins = minimumMins;\r
+                       }\r
+                       if (frequency.indexOf("day") > -1) {\r
+                               // convert to minutes\r
+                               mins *= 1440;\r
+                       } else if (frequency.indexOf("hour") > -1) {\r
+                               // convert to minutes\r
+                               mins *= 60;\r
                        }\r
-               }\r
-               if (frequency.indexOf("day") > -1) {\r
-                       // convert to minutes\r
-                       mins *= 1440;\r
-               } else if (frequency.indexOf("hour") > -1) {\r
-                       // convert to minutes\r
-                       mins *= 60;\r
                }\r
                return mins;\r
        }\r
index fb38ffd3266c39cdfb67772e7af230651a2e76b4..ef506ef4a48622fe4044a643fb29708d2d0db845 100644 (file)
@@ -100,9 +100,9 @@ public class TimeUtilsTest extends GitblitUnitTest {
 \r
        @Test\r
        public void testFrequency() {\r
-               assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins"));\r
-               assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins"));\r
-               assertEquals(600, TimeUtils.convertFrequencyToMinutes("10 hours"));\r
-               assertEquals(14400, TimeUtils.convertFrequencyToMinutes(" 10 days "));\r
+               assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins", 5));\r
+               assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins", 5));\r
+               assertEquals(600, TimeUtils.convertFrequencyToMinutes("10 hours", 5));\r
+               assertEquals(14400, TimeUtils.convertFrequencyToMinutes(" 10 days ", 5));\r
        }\r
 }\r