diff options
author | James Moger <james.moger@gitblit.com> | 2013-01-03 17:22:21 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-01-03 17:22:21 -0500 |
commit | eee533b4583854b9c875221f1c1f50dfb092868d (patch) | |
tree | 8b3c9fb798e45647138b0b93c91d3e6ef743d336 | |
parent | 7ec9d3d1b460db339db2770f3aa81af9826deed3 (diff) | |
download | gitblit-eee533b4583854b9c875221f1c1f50dfb092868d.tar.gz gitblit-eee533b4583854b9c875221f1c1f50dfb092868d.zip |
Cache and re-use project markdown content (issue-172)
-rw-r--r-- | src/com/gitblit/GitBlit.java | 29 | ||||
-rw-r--r-- | src/com/gitblit/models/ProjectModel.java | 2 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/ProjectPage.java | 33 |
3 files changed, 37 insertions, 27 deletions
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 96333a07..30071bb6 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -154,6 +154,10 @@ public class GitBlit implements ServletContextListener { private final Map<String, ProjectModel> projectCache = new ConcurrentHashMap<String, ProjectModel>();
private final AtomicReference<String> repositoryListSettingsChecksum = new AtomicReference<String>("");
+
+ private final ObjectCache<String> projectMarkdownCache = new ObjectCache<String>();
+
+ private final ObjectCache<String> projectRepositoriesMarkdownCache = new ObjectCache<String>();
private ServletContext servletContext;
@@ -1402,7 +1406,30 @@ public class GitBlit implements ServletContextListener { }
project.title = projectConfigs.getString("project", name, "title");
project.description = projectConfigs.getString("project", name, "description");
- configs.put(name.toLowerCase(), project);
+
+ // project markdown
+ File pmkd = new File(getRepositoriesFolder(), (project.isRoot ? "" : name) + "/project.mkd");
+ if (pmkd.exists()) {
+ Date lm = new Date(pmkd.lastModified());
+ if (!projectMarkdownCache.hasCurrent(name, lm)) {
+ String mkd = com.gitblit.utils.FileUtils.readContent(pmkd, "\n");
+ projectMarkdownCache.updateObject(name, lm, mkd);
+ }
+ project.projectMarkdown = projectMarkdownCache.getObject(name);
+ }
+
+ // project repositories markdown
+ File rmkd = new File(getRepositoriesFolder(), (project.isRoot ? "" : name) + "/repositories.mkd");
+ if (rmkd.exists()) {
+ Date lm = new Date(rmkd.lastModified());
+ if (!projectRepositoriesMarkdownCache.hasCurrent(name, lm)) {
+ String mkd = com.gitblit.utils.FileUtils.readContent(rmkd, "\n");
+ projectRepositoriesMarkdownCache.updateObject(name, lm, mkd);
+ }
+ project.repositoriesMarkdown = projectRepositoriesMarkdownCache.getObject(name);
+ }
+
+ configs.put(name.toLowerCase(), project);
}
projectCache.clear();
projectCache.putAll(configs);
diff --git a/src/com/gitblit/models/ProjectModel.java b/src/com/gitblit/models/ProjectModel.java index 189a409b..9e5d5233 100644 --- a/src/com/gitblit/models/ProjectModel.java +++ b/src/com/gitblit/models/ProjectModel.java @@ -39,6 +39,8 @@ public class ProjectModel implements Serializable, Comparable<ProjectModel> { public String description;
public final Set<String> repositories = new HashSet<String>();
+ public String projectMarkdown;
+ public String repositoriesMarkdown;
public Date lastChange;
public final boolean isRoot;
diff --git a/src/com/gitblit/wicket/pages/ProjectPage.java b/src/com/gitblit/wicket/pages/ProjectPage.java index e10ca900..7eba0331 100644 --- a/src/com/gitblit/wicket/pages/ProjectPage.java +++ b/src/com/gitblit/wicket/pages/ProjectPage.java @@ -15,9 +15,6 @@ */
package com.gitblit.wicket.pages;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -37,7 +34,6 @@ import org.apache.wicket.markup.html.link.ExternalLink; import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
-import org.eclipse.jgit.lib.Constants;
import com.gitblit.GitBlit;
import com.gitblit.Keys;
@@ -46,7 +42,6 @@ import com.gitblit.models.Activity; import com.gitblit.models.Metric;
import com.gitblit.models.ProjectModel;
import com.gitblit.models.RepositoryModel;
-import com.gitblit.models.UserModel;
import com.gitblit.utils.ActivityUtils;
import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.StringUtils;
@@ -111,23 +106,14 @@ public class ProjectPage extends RootPage { add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(project.getDisplayName(),
null), feedLink));
- final String projectPath;
- if (project.isRoot) {
- projectPath = "";
- } else {
- projectPath = projectName + "/";
- }
-
// project markdown message
- File pmkd = new File(GitBlit.getRepositoriesFolder(), projectPath + "project.mkd");
- String pmessage = readMarkdown(projectName, pmkd);
+ String pmessage = transformMarkdown(project.projectMarkdown);
Component projectMessage = new Label("projectMessage", pmessage)
.setEscapeModelStrings(false).setVisible(pmessage.length() > 0);
add(projectMessage);
// markdown message above repositories list
- File rmkd = new File(GitBlit.getRepositoriesFolder(), projectPath + "repositories.mkd");
- String rmessage = readMarkdown(projectName, rmkd);
+ String rmessage = transformMarkdown(project.repositoriesMarkdown);
Component repositoriesMessage = new Label("repositoriesMessage", rmessage)
.setEscapeModelStrings(false).setVisible(rmessage.length() > 0);
add(repositoriesMessage);
@@ -352,20 +338,15 @@ public class ProjectPage extends RootPage { }
return menu;
}
-
-
- private String readMarkdown(String projectName, File projectMessage) {
+
+ private String transformMarkdown(String markdown) {
String message = "";
- if (projectMessage.exists()) {
+ if (!StringUtils.isEmpty(markdown)) {
// Read user-supplied message
try {
- FileInputStream fis = new FileInputStream(projectMessage);
- InputStreamReader reader = new InputStreamReader(fis,
- Constants.CHARACTER_ENCODING);
- message = MarkdownUtils.transformMarkdown(reader);
- reader.close();
+ message = MarkdownUtils.transformMarkdown(markdown);
} catch (Throwable t) {
- message = getString("gb.failedToRead") + " " + projectMessage;
+ message = getString("gb.failedToRead") + " " + markdown;
warn(message, t);
}
}
|