]> source.dussan.org Git - gitblit.git/commitdiff
Global and per-repository setting to throttle prolific repos in Activity page (issue...
authorJames Moger <james.moger@gitblit.com>
Wed, 5 Dec 2012 22:20:06 +0000 (17:20 -0500)
committerJames Moger <james.moger@gitblit.com>
Wed, 5 Dec 2012 22:20:06 +0000 (17:20 -0500)
distrib/gitblit.properties
docs/04_releases.mkd
src/com/gitblit/GitBlit.java
src/com/gitblit/client/EditRepositoryDialog.java
src/com/gitblit/models/RepositoryModel.java
src/com/gitblit/utils/ActivityUtils.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/pages/EditRepositoryPage.html
src/com/gitblit/wicket/pages/EditRepositoryPage.java

index d57f9ba1a8f15a38e1c54630cd1ae97d27de6485..e3d72211fa033138174c4da9a5bad430998cf3c7 100644 (file)
@@ -522,6 +522,14 @@ web.shortCommitIdLength = 6
 # SINCE 0.8.0\r
 web.allowFlashCopyToClipboard = true\r
 \r
+# Default maximum number of commits that a repository may contribute to the\r
+# activity page, regardless of the selected duration.  This setting may be valuable\r
+# for an extremely busy server.  This value may also be configed per-repository\r
+# in Edit Repository. 0 disables this throttle.\r
+#\r
+# SINCE 1.2.0\r
+web.maxActivityCommits = 0\r
+\r
 # Default number of entries to include in RSS Syndication links\r
 #\r
 # SINCE 0.5.0\r
index 7dd4e74718c3e822dfdb05fc50046eae02f5c539..52bd51e70f74dc33db41db8510a3fb0f84cbf632 100644 (file)
@@ -73,6 +73,7 @@ This is extreme and should be considered carefully since it affects every https
 \r
 #### changes\r
 \r
+- Added optional global and per-repository activity page commit contribution throttle to help tame *really* active repositories (issue 173)\r
 - Added support for symlinks in tree page and commit page (issue 171)\r
 - All access restricted servlets (e.g. DownloadZip, RSS, etc) will try to authenticate using X509 certificates, container principals, cookies, and BASIC headers, in that order.\r
 - Added *groovy* and *scala* to *web.prettyPrintExtensions*\r
index 02906ee99986dd7949edd4ce8776b3466fdc84ff..c2d4a85a42204230f7022d9f7611a9acf4cea1bd 100644 (file)
@@ -1602,6 +1602,7 @@ public class GitBlit implements ServletContextListener {
                        } catch (Exception e) {\r
                                model.lastGC = new Date(0);\r
                        }\r
+                       model.maxActivityCommits = getConfig(config, "maxActivityCommits", settings.getInteger(Keys.web.maxActivityCommits, 0));\r
                        model.origin = config.getString("remote", "origin", "url");\r
                        if (model.origin != null) {\r
                                model.origin = model.origin.replace('\\', '/');\r
@@ -2068,10 +2069,21 @@ public class GitBlit implements ServletContextListener {
                                repository.federationStrategy.name());\r
                config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated);\r
                config.setString(Constants.CONFIG_GITBLIT, null, "gcThreshold", repository.gcThreshold);\r
-               config.setInt(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod);\r
+               if (repository.gcPeriod == settings.getInteger(Keys.git.defaultGarbageCollectionPeriod, 7)) {\r
+                       // use default from config\r
+                       config.unset(Constants.CONFIG_GITBLIT, null, "gcPeriod");\r
+               } else {\r
+                       config.setInt(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod);\r
+               }\r
                if (repository.lastGC != null) {\r
                        config.setString(Constants.CONFIG_GITBLIT, null, "lastGC", new SimpleDateFormat(Constants.ISO8601).format(repository.lastGC));\r
                }\r
+               if (repository.maxActivityCommits == settings.getInteger(Keys.web.maxActivityCommits, 0)) {\r
+                       // use default from config\r
+                       config.unset(Constants.CONFIG_GITBLIT, null, "maxActivityCommits");\r
+               } else {\r
+                       config.setInt(Constants.CONFIG_GITBLIT, null, "maxActivityCommits", repository.maxActivityCommits);\r
+               }\r
 \r
                updateList(config, "federationSets", repository.federationSets);\r
                updateList(config, "preReceiveScript", repository.preReceiveScripts);\r
index a9274964aaf29bcc25843e7b32d47deadc692138..aa6ad58d12e1c9a4d7d08a6171f4a898a8c24399 100644 (file)
@@ -124,6 +124,8 @@ public class EditRepositoryDialog extends JDialog {
        private JComboBox gcPeriod;\r
        \r
        private JTextField gcThreshold;\r
+       \r
+       private JComboBox maxActivityCommits;\r
 \r
        private RegistrantPermissionsPanel usersPalette;\r
 \r
@@ -225,6 +227,10 @@ public class EditRepositoryDialog extends JDialog {
                isFrozen = new JCheckBox(Translation.get("gb.isFrozenDescription"),\r
                                anRepository.isFrozen);\r
 \r
+               maxActivityCommits = new JComboBox(new Integer [] { 0, 25, 50, 75, 100, 150, 250, 500 });\r
+               maxActivityCommits.setSelectedItem(anRepository.maxActivityCommits);\r
+\r
+\r
                mailingListsField = new JTextField(\r
                                ArrayUtils.isEmpty(anRepository.mailingLists) ? ""\r
                                                : StringUtils.flattenStrings(anRepository.mailingLists,\r
@@ -314,6 +320,8 @@ public class EditRepositoryDialog extends JDialog {
                                                skipSizeCalculation));\r
                fieldsPanel.add(newFieldPanel(Translation.get("gb.skipSummaryMetrics"),\r
                                skipSummaryMetrics));\r
+               fieldsPanel.add(newFieldPanel(Translation.get("gb.maxActivityCommits"),\r
+                               maxActivityCommits));\r
                fieldsPanel.add(newFieldPanel(Translation.get("gb.mailingLists"),\r
                                mailingListsField));\r
 \r
@@ -561,6 +569,7 @@ public class EditRepositoryDialog extends JDialog {
                repository.showReadme = showReadme.isSelected();\r
                repository.skipSizeCalculation = skipSizeCalculation.isSelected();\r
                repository.skipSummaryMetrics = skipSummaryMetrics.isSelected();\r
+               repository.maxActivityCommits = (Integer) maxActivityCommits.getSelectedItem();\r
                \r
                repository.isFrozen = isFrozen.isSelected();\r
                repository.allowForks = allowForks.isSelected();\r
index ed9e7188d0a03b964cde0ff5a201012f8709ae21..5be33a2d9612c01be20ac888a44cf2156539011d 100644 (file)
@@ -78,6 +78,7 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel
        public boolean verifyCommitter;\r
        public String gcThreshold;\r
        public int gcPeriod;\r
+       public int maxActivityCommits;\r
        \r
        public transient boolean isCollectingGarbage;\r
        public Date lastGC;\r
index e389e642bd10093133cd62d5cd0113a210205286..80aaebbbbd56ad44be66dc7de45df965223f174d 100644 (file)
@@ -106,7 +106,11 @@ public class ActivityUtils {
                                        }\r
                                        List<RevCommit> commits = JGitUtils.getRevLog(repository,\r
                                                        branch, thresholdDate);\r
-                                       for (RevCommit commit : commits) {\r
+                                       if (model.maxActivityCommits > 0 && commits.size() > model.maxActivityCommits) {\r
+                                               // trim commits to maximum count\r
+                                               commits = commits.subList(0,  model.maxActivityCommits);\r
+                                       }\r
+                                       for (RevCommit commit : commits) {                                              \r
                                                Date date = JGitUtils.getCommitDate(commit);\r
                                                String dateStr = df.format(date);\r
                                                if (!activity.containsKey(dateStr)) {\r
index 6ee12990fb246a0efb60f65907bf4adf9de9ea6a..9ee9f39725b71c2adde8cd28cc1f1df7325d64f3 100644 (file)
@@ -430,4 +430,7 @@ gb.pleaseGenerateClientCertificate = Please generate a client certificate for {0
 gb.clientCertificateBundleSent = Client certificate bundle for {0} sent\r
 gb.enterKeystorePassword = Please enter the Gitblit keystore password\r
 gb.warning = warning\r
-gb.jceWarning = Your Java Runtime Environment does not have the \"JCE Unlimited Strength Jurisdiction Policy\" files.\nThis will limit the length of passwords you may use to encrypt your keystores to 7 characters.\nThese policy files are an optional download from Oracle.\n\nWould you like to continue and generate the certificate infrastructure anyway?\n\nAnswering No will direct your browser to Oracle's download page so that you may download the policy files.
\ No newline at end of file
+gb.jceWarning = Your Java Runtime Environment does not have the \"JCE Unlimited Strength Jurisdiction Policy\" files.\nThis will limit the length of passwords you may use to encrypt your keystores to 7 characters.\nThese policy files are an optional download from Oracle.\n\nWould you like to continue and generate the certificate infrastructure anyway?\n\nAnswering No will direct your browser to Oracle's download page so that you may download the policy files.\r
+gb.maxActivityCommits = max activity commits\r
+gb.maxActivityCommitsDescription = maximum number of commits to contribute to the Activity page\r
+gb.noMaximum = no maximum
\ No newline at end of file
index cd3c46626ab04c3463166a4860f802a88c3bbca4..60893f444ef78a3b81de0d86268ccefb2c043fde 100644 (file)
@@ -39,8 +39,9 @@
                                <tr><th><wicket:message key="gb.showReadme"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="showReadme" tabindex="10" /> &nbsp;<span class="help-inline"><wicket:message key="gb.showReadmeDescription"></wicket:message></span></label></td></tr>\r
                                <tr><th><wicket:message key="gb.skipSizeCalculation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="skipSizeCalculation" tabindex="11" /> &nbsp;<span class="help-inline"><wicket:message key="gb.skipSizeCalculationDescription"></wicket:message></span></label></td></tr>\r
                                <tr><th><wicket:message key="gb.skipSummaryMetrics"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="skipSummaryMetrics" tabindex="12" /> &nbsp;<span class="help-inline"><wicket:message key="gb.skipSummaryMetricsDescription"></wicket:message></span></label></td></tr>\r
+                               <tr><th><wicket:message key="gb.maxActivityCommits"></wicket:message></th><td class="edit"><select class="span2" wicket:id="maxActivityCommits" tabindex="13" /> &nbsp;<span class="help-inline"><wicket:message key="gb.maxActivityCommitsDescription"></wicket:message></span></td></tr>\r
                                <tr><th colspan="2"><hr/></th></tr>\r
-                               <tr><th><wicket:message key="gb.mailingLists"></wicket:message></th><td class="edit"><input class="span8" type="text" wicket:id="mailingLists" size="40" tabindex="13" /></td></tr>\r
+                               <tr><th><wicket:message key="gb.mailingLists"></wicket:message></th><td class="edit"><input class="span8" type="text" wicket:id="mailingLists" size="40" tabindex="14" /></td></tr>\r
                        </tbody>\r
                </table>\r
                </div>\r
                <div class="tab-pane" id="permissions">\r
                        <table class="plain">\r
                                <tbody class="settings">\r
-                                       <tr><th><wicket:message key="gb.owner"></wicket:message></th><td class="edit"><select class="span2" wicket:id="owner" tabindex="14" /> &nbsp;<span class="help-inline"><wicket:message key="gb.ownerDescription"></wicket:message></span></td></tr>\r
+                                       <tr><th><wicket:message key="gb.owner"></wicket:message></th><td class="edit"><select class="span2" wicket:id="owner" tabindex="15" /> &nbsp;<span class="help-inline"><wicket:message key="gb.ownerDescription"></wicket:message></span></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
-                                       <tr><th><wicket:message key="gb.accessRestriction"></wicket:message></th><td class="edit"><select class="span4" wicket:id="accessRestriction" tabindex="15" /></td></tr>\r
+                                       <tr><th><wicket:message key="gb.accessRestriction"></wicket:message></th><td class="edit"><select class="span4" wicket:id="accessRestriction" tabindex="16" /></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
                                        <tr><th><wicket:message key="gb.authorizationControl"></wicket:message></th><td style="padding:2px;"><span class="authorizationControl" wicket:id="authorizationControl"></span></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
-                                       <tr><th><wicket:message key="gb.isFrozen"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="isFrozen" tabindex="18" /> &nbsp;<span class="help-inline"><wicket:message key="gb.isFrozenDescription"></wicket:message></span></label></td></tr>\r
-                                       <tr><th><wicket:message key="gb.allowForks"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="allowForks" tabindex="19" /> &nbsp;<span class="help-inline"><wicket:message key="gb.allowForksDescription"></wicket:message></span></label></td></tr>\r
-                                       <tr><th><wicket:message key="gb.verifyCommitter"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="verifyCommitter" tabindex="20" /> &nbsp;<span class="help-inline"><wicket:message key="gb.verifyCommitterDescription"></wicket:message></span><br/><span class="help-inline" style="padding-left:10px;"><wicket:message key="gb.verifyCommitterNote"></wicket:message></span></label></td></tr>\r
+                                       <tr><th><wicket:message key="gb.isFrozen"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="isFrozen" tabindex="17" /> &nbsp;<span class="help-inline"><wicket:message key="gb.isFrozenDescription"></wicket:message></span></label></td></tr>\r
+                                       <tr><th><wicket:message key="gb.allowForks"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="allowForks" tabindex="18" /> &nbsp;<span class="help-inline"><wicket:message key="gb.allowForksDescription"></wicket:message></span></label></td></tr>\r
+                                       <tr><th><wicket:message key="gb.verifyCommitter"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="verifyCommitter" tabindex="19" /> &nbsp;<span class="help-inline"><wicket:message key="gb.verifyCommitterDescription"></wicket:message></span><br/><span class="help-inline" style="padding-left:10px;"><wicket:message key="gb.verifyCommitterNote"></wicket:message></span></label></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
                                        <tr><th><wicket:message key="gb.userPermissions"></wicket:message></th><td style="padding:2px;"><span wicket:id="users"></span></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
@@ -70,7 +71,7 @@
                <div class="tab-pane" id="federation">\r
                        <table class="plain">\r
                                <tbody class="settings">\r
-                                       <tr><th><wicket:message key="gb.federationStrategy"></wicket:message></th><td class="edit"><select class="span4" wicket:id="federationStrategy" tabindex="21" /></td></tr>\r
+                                       <tr><th><wicket:message key="gb.federationStrategy"></wicket:message></th><td class="edit"><select class="span4" wicket:id="federationStrategy" tabindex="20" /></td></tr>\r
                                        <tr><th><wicket:message key="gb.federationSets"></wicket:message></th><td style="padding:2px;"><span wicket:id="federationSets"></span></td></tr>\r
                                </tbody>\r
                        </table>\r
index 9de8244a1d675ad46285466ba708d4aac0763eca..7f66f688e4da2310673d53d02e0d80ab827363c2 100644 (file)
@@ -414,6 +414,9 @@ public class EditRepositoryPage extends RootSubPage {
                form.add(new CheckBox("showReadme"));\r
                form.add(new CheckBox("skipSizeCalculation"));\r
                form.add(new CheckBox("skipSummaryMetrics"));\r
+               List<Integer> maxActivityCommits  = Arrays.asList(0, 25, 50, 75, 100, 150, 200, 250, 500 );\r
+               form.add(new DropDownChoice<Integer>("maxActivityCommits", maxActivityCommits, new MaxActivityCommitsRenderer()));\r
+\r
                mailingLists = new Model<String>(ArrayUtils.isEmpty(repositoryModel.mailingLists) ? ""\r
                                : StringUtils.flattenStrings(repositoryModel.mailingLists, " "));\r
                form.add(new TextField<String>("mailingLists", mailingLists));\r
@@ -654,4 +657,26 @@ public class EditRepositoryPage extends RootSubPage {
                }\r
        }\r
        \r
+       private class MaxActivityCommitsRenderer implements IChoiceRenderer<Integer> {\r
+\r
+               private static final long serialVersionUID = 1L;\r
+\r
+               public MaxActivityCommitsRenderer() {\r
+               }\r
+\r
+               @Override\r
+               public String getDisplayValue(Integer value) {\r
+                       if (value == 0) {\r
+                               return getString("gb.noMaximum");\r
+                       } else {\r
+                               return value + " " + getString("gb.commits");\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public String getIdValue(Integer value, int index) {\r
+                       return Integer.toString(index);\r
+               }\r
+       }\r
+       \r
 }\r