diff options
author | James Moger <james.moger@gitblit.com> | 2013-01-03 17:21:32 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-01-03 17:21:32 -0500 |
commit | 7ec9d3d1b460db339db2770f3aa81af9826deed3 (patch) | |
tree | 6af772d193b8aabd937d8f8a1c36b39d09d13946 /src | |
parent | 15dcc074a7db2b3dae95c37e7e8625139f0e37da (diff) | |
download | gitblit-7ec9d3d1b460db339db2770f3aa81af9826deed3.tar.gz gitblit-7ec9d3d1b460db339db2770f3aa81af9826deed3.zip |
Build project models from repository cache, when possible (issue-172)
Diffstat (limited to 'src')
-rw-r--r-- | src/com/gitblit/GitBlit.java | 43 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/ProjectPage.java | 4 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/ProjectsPage.java | 7 | ||||
-rw-r--r-- | src/com/gitblit/wicket/panels/RepositoriesPanel.java | 18 |
4 files changed, 53 insertions, 19 deletions
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 3dcd5a09..96333a07 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -1526,6 +1526,49 @@ public class GitBlit implements ServletContextListener { }
/**
+ * Returns the list of project models that are referenced by the supplied
+ * repository model list. This is an alternative method exists to ensure
+ * Gitblit does not call getRepositoryModels(UserModel) twice in a request.
+ *
+ * @param repositoryModels
+ * @param includeUsers
+ * @return a list of project models
+ */
+ public List<ProjectModel> getProjectModels(List<RepositoryModel> repositoryModels, boolean includeUsers) {
+ Map<String, ProjectModel> projects = new LinkedHashMap<String, ProjectModel>();
+ for (RepositoryModel repository : repositoryModels) {
+ if (!includeUsers && repository.isPersonalRepository()) {
+ // exclude personal repositories
+ continue;
+ }
+ if (!projects.containsKey(repository.projectPath)) {
+ ProjectModel project = getProjectModel(repository.projectPath);
+ if (project == null) {
+ logger.warn(MessageFormat.format("excluding project \"{0}\" from project list because it is empty!",
+ repository.projectPath));
+ continue;
+ }
+ projects.put(repository.projectPath, project);
+ // clear the repo list in the project because that is the system
+ // list, not the user-accessible list and start building the
+ // user-accessible list
+ project.repositories.clear();
+ project.repositories.add(repository.name);
+ project.lastChange = repository.lastChange;
+ } else {
+ // update the user-accessible list
+ // this is used for repository count
+ ProjectModel project = projects.get(repository.projectPath);
+ project.repositories.add(repository.name);
+ if (project.lastChange.before(repository.lastChange)) {
+ project.lastChange = repository.lastChange;
+ }
+ }
+ }
+ return new ArrayList<ProjectModel>(projects.values());
+ }
+
+ /**
* Workaround JGit. I need to access the raw config object directly in order
* to see if the config is dirty so that I can reload a repository model.
* If I use the stock JGit method to get the config it already reloads the
diff --git a/src/com/gitblit/wicket/pages/ProjectPage.java b/src/com/gitblit/wicket/pages/ProjectPage.java index bc546dfc..e10ca900 100644 --- a/src/com/gitblit/wicket/pages/ProjectPage.java +++ b/src/com/gitblit/wicket/pages/ProjectPage.java @@ -300,8 +300,8 @@ public class ProjectPage extends RootPage { @Override
protected List<ProjectModel> getProjectModels() {
if (projectModels.isEmpty()) {
- final UserModel user = GitBlitWebSession.get().getUser();
- List<ProjectModel> projects = GitBlit.self().getProjectModels(user, false);
+ List<RepositoryModel> repositories = getRepositoryModels();
+ List<ProjectModel> projects = GitBlit.self().getProjectModels(repositories, false);
projectModels.addAll(projects);
}
return projectModels;
diff --git a/src/com/gitblit/wicket/pages/ProjectsPage.java b/src/com/gitblit/wicket/pages/ProjectsPage.java index 4e3e6309..7f0b002e 100644 --- a/src/com/gitblit/wicket/pages/ProjectsPage.java +++ b/src/com/gitblit/wicket/pages/ProjectsPage.java @@ -36,7 +36,6 @@ import org.eclipse.jgit.lib.Constants; import com.gitblit.GitBlit;
import com.gitblit.Keys;
import com.gitblit.models.ProjectModel;
-import com.gitblit.models.UserModel;
import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebSession;
@@ -48,8 +47,6 @@ import com.gitblit.wicket.panels.LinkPanel; public class ProjectsPage extends RootPage {
- List<ProjectModel> projectModels = new ArrayList<ProjectModel>();
-
public ProjectsPage() {
super();
setup(null);
@@ -67,9 +64,7 @@ public class ProjectsPage extends RootPage { @Override
protected List<ProjectModel> getProjectModels() {
- final UserModel user = GitBlitWebSession.get().getUser();
- List<ProjectModel> projects = GitBlit.self().getProjectModels(user, false);
- return projects;
+ return GitBlit.self().getProjectModels(getRepositoryModels(), false);
}
private void setup(PageParameters params) {
diff --git a/src/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/com/gitblit/wicket/panels/RepositoriesPanel.java index d3b8ddbe..976c517f 100644 --- a/src/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -123,22 +123,18 @@ public class RepositoriesPanel extends BasePanel { if (rootRepositories.size() > 0) {
// inject the root repositories at the top of the page
- String rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " ");
- roots.add(0, rootPath);
- groups.put(rootPath, rootRepositories);
+ roots.add(0, "");
+ groups.put("", rootRepositories);
}
- Map<String, ProjectModel> projects = new HashMap<String, ProjectModel>();
- for (ProjectModel project : GitBlit.self().getProjectModels(user, true)) {
- projects.put(project.name, project);
- }
List<RepositoryModel> groupedModels = new ArrayList<RepositoryModel>();
for (String root : roots) {
List<RepositoryModel> subModels = groups.get(root);
- GroupRepositoryModel group = new GroupRepositoryModel(root, subModels.size());
- if (projects.containsKey(root)) {
- group.title = projects.get(root).title;
- group.description = projects.get(root).description;
+ ProjectModel project = GitBlit.self().getProjectModel(root);
+ GroupRepositoryModel group = new GroupRepositoryModel(project.name, subModels.size());
+ if (project != null) {
+ group.title = project.title;
+ group.description = project.description;
}
groupedModels.add(group);
Collections.sort(subModels);
|