]> source.dussan.org Git - gitblit.git/commitdiff
Build project models from repository cache, when possible (issue-172)
authorJames Moger <james.moger@gitblit.com>
Thu, 3 Jan 2013 22:21:32 +0000 (17:21 -0500)
committerJames Moger <james.moger@gitblit.com>
Thu, 3 Jan 2013 22:21:32 +0000 (17:21 -0500)
docs/04_releases.mkd
src/com/gitblit/GitBlit.java
src/com/gitblit/wicket/pages/ProjectPage.java
src/com/gitblit/wicket/pages/ProjectsPage.java
src/com/gitblit/wicket/panels/RepositoriesPanel.java

index faec56a09eefccb95d8978f03f82ffd71b0a9b38..32fb0297f019248c4a886c1ed4e2d43bb3105e07 100644 (file)
@@ -7,6 +7,7 @@
 #### fixes\r
 \r
 - Fixed nullpointer when using web.allowForking = true && git.cacheRepositoryList = false (issue 182)\r
+- Build project models from the repository model cache, when possible, to reduce page load time (issue 172)\r
 - Fixed loading of Brazilian Portuguese translation from *nix server (github/inaiat)\r
 \r
 ### Older Releases\r
index 3dcd5a0991201c784a96f5de3ab137fbaa9f9c69..96333a07e242c01f62ca4a4b194972f25fd37386 100644 (file)
@@ -1525,6 +1525,49 @@ public class GitBlit implements ServletContextListener {
                return project;\r
        }\r
        \r
+       /**\r
+        * Returns the list of project models that are referenced by the supplied\r
+        * repository model     list.  This is an alternative method exists to ensure\r
+        * Gitblit does not call getRepositoryModels(UserModel) twice in a request.\r
+        * \r
+        * @param repositoryModels\r
+        * @param includeUsers\r
+        * @return a list of project models\r
+        */\r
+       public List<ProjectModel> getProjectModels(List<RepositoryModel> repositoryModels, boolean includeUsers) {\r
+               Map<String, ProjectModel> projects = new LinkedHashMap<String, ProjectModel>();\r
+               for (RepositoryModel repository : repositoryModels) {\r
+                       if (!includeUsers && repository.isPersonalRepository()) {\r
+                               // exclude personal repositories\r
+                               continue;\r
+                       }\r
+                       if (!projects.containsKey(repository.projectPath)) {\r
+                               ProjectModel project = getProjectModel(repository.projectPath);\r
+                               if (project == null) {\r
+                                       logger.warn(MessageFormat.format("excluding project \"{0}\" from project list because it is empty!",\r
+                                                       repository.projectPath));\r
+                                       continue;\r
+                               }\r
+                               projects.put(repository.projectPath, project);\r
+                               // clear the repo list in the project because that is the system\r
+                               // list, not the user-accessible list and start building the\r
+                               // user-accessible list\r
+                               project.repositories.clear();\r
+                               project.repositories.add(repository.name);\r
+                               project.lastChange = repository.lastChange;\r
+                       } else {\r
+                               // update the user-accessible list\r
+                               // this is used for repository count\r
+                               ProjectModel project = projects.get(repository.projectPath);\r
+                               project.repositories.add(repository.name);\r
+                               if (project.lastChange.before(repository.lastChange)) {\r
+                                       project.lastChange = repository.lastChange;\r
+                               }\r
+                       }\r
+               }\r
+               return new ArrayList<ProjectModel>(projects.values());\r
+       }\r
+       \r
        /**\r
         * Workaround JGit.  I need to access the raw config object directly in order\r
         * to see if the config is dirty so that I can reload a repository model.\r
index bc546dfc38a64510563b87844d3adf4401ac3238..e10ca900374aea4cd4af51d37ebcae29caefb82b 100644 (file)
@@ -300,8 +300,8 @@ public class ProjectPage extends RootPage {
        @Override\r
        protected List<ProjectModel> getProjectModels() {\r
                if (projectModels.isEmpty()) {\r
-                       final UserModel user = GitBlitWebSession.get().getUser();\r
-                       List<ProjectModel> projects = GitBlit.self().getProjectModels(user, false);\r
+                       List<RepositoryModel> repositories = getRepositoryModels();\r
+                       List<ProjectModel> projects = GitBlit.self().getProjectModels(repositories, false);\r
                        projectModels.addAll(projects);\r
                }\r
                return projectModels;\r
index 4e3e6309cb8f54a576ca56aab2f150a8d5419bb1..7f0b002eacd9b566f35cb2217ce3c79b696c8dcd 100644 (file)
@@ -36,7 +36,6 @@ import org.eclipse.jgit.lib.Constants;
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.ProjectModel;\r
-import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.MarkdownUtils;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
@@ -48,8 +47,6 @@ import com.gitblit.wicket.panels.LinkPanel;
 \r
 public class ProjectsPage extends RootPage {\r
 \r
-       List<ProjectModel> projectModels = new ArrayList<ProjectModel>();\r
-\r
        public ProjectsPage() {\r
                super();\r
                setup(null);\r
@@ -67,9 +64,7 @@ public class ProjectsPage extends RootPage {
        \r
        @Override\r
        protected List<ProjectModel> getProjectModels() {\r
-               final UserModel user = GitBlitWebSession.get().getUser();\r
-               List<ProjectModel> projects = GitBlit.self().getProjectModels(user, false);\r
-               return projects;\r
+               return GitBlit.self().getProjectModels(getRepositoryModels(), false);\r
        }\r
 \r
        private void setup(PageParameters params) {\r
index d3b8ddbea54e48fbf7434a53ed5676f662533b48..976c517f0350b0ffc645ec61a33e3c26ce781747 100644 (file)
@@ -123,22 +123,18 @@ public class RepositoriesPanel extends BasePanel {
 \r
                        if (rootRepositories.size() > 0) {\r
                                // inject the root repositories at the top of the page\r
-                               String rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " ");\r
-                               roots.add(0, rootPath);\r
-                               groups.put(rootPath, rootRepositories);\r
+                               roots.add(0, "");\r
+                               groups.put("", rootRepositories);\r
                        }\r
                                                \r
-                       Map<String, ProjectModel> projects = new HashMap<String, ProjectModel>();\r
-                       for (ProjectModel project : GitBlit.self().getProjectModels(user, true)) {\r
-                               projects.put(project.name, project);\r
-                       }\r
                        List<RepositoryModel> groupedModels = new ArrayList<RepositoryModel>();\r
                        for (String root : roots) {\r
                                List<RepositoryModel> subModels = groups.get(root);\r
-                               GroupRepositoryModel group = new GroupRepositoryModel(root, subModels.size());\r
-                               if (projects.containsKey(root)) {\r
-                                       group.title = projects.get(root).title;\r
-                                       group.description = projects.get(root).description;\r
+                               ProjectModel project = GitBlit.self().getProjectModel(root);\r
+                               GroupRepositoryModel group = new GroupRepositoryModel(project.name, subModels.size());\r
+                               if (project != null) {\r
+                                       group.title = project.title;\r
+                                       group.description = project.description;\r
                                }\r
                                groupedModels.add(group);\r
                                Collections.sort(subModels);\r