#### 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
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
@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
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
\r
public class ProjectsPage extends RootPage {\r
\r
- List<ProjectModel> projectModels = new ArrayList<ProjectModel>();\r
-\r
public ProjectsPage() {\r
super();\r
setup(null);\r
\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
\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