You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/03/20 19:46:36 UTC
[03/17] git commit: [#7051] Improve sitemap performance when many
tools installed
[#7051] Improve sitemap performance when many tools installed
- Add paging to admin tools screen and tool list screen.
- Include at most 10 tools of each type in a project sitemap.
Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/e08764bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/e08764bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/e08764bf
Branch: refs/heads/cj/6701
Commit: e08764bf700c16372b169a7d0561d3037dca0bcb
Parents: ce89f95
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Wed Mar 12 20:29:15 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Mar 18 16:31:07 2014 +0000
----------------------------------------------------------------------
Allura/allura/controllers/project.py | 16 ++++++++--
Allura/allura/ext/admin/admin_main.py | 11 +++++--
.../ext/admin/templates/project_tools.html | 1 +
Allura/allura/model/project.py | 33 +++++++++++++++++---
Allura/allura/templates/tool_list.html | 2 ++
5 files changed, 53 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index ea2e6d5..aedae62 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -315,11 +315,21 @@ class ToolListController(object):
"""Renders a list of all tools of a given type in the current project."""
@expose('jinja:allura:templates/tool_list.html')
- def _default(self, tool_name, *args, **kw):
+ def _default(self, tool_name, page=0, limit=200, **kw):
tool_name = tool_name.lower()
- entries = [e for e in c.project.sitemap()
+ entries = [e for e in c.project.sitemap(per_tool_limit=None)
if e.tool_name and e.tool_name.lower() == tool_name]
- return dict(entries=entries, type=g.entry_points['tool'][tool_name].tool_label if entries else None)
+ c.page_list = W.page_list
+ total_entries = len(entries)
+ limit, page = h.paging_sanitizer(limit, page, total_entries)
+ start = page * limit
+ return dict(
+ page=page,
+ limit=limit,
+ total_entries=total_entries,
+ entries=entries[start:start + limit],
+ type=g.entry_points['tool'][tool_name].tool_label if entries else None,
+ )
class ProjectController(FeedController):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index e19572b..696f14d 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -261,15 +261,22 @@ class ProjectAdminController(BaseController):
@without_trailing_slash
@expose('jinja:allura.ext.admin:templates/project_tools.html')
- def tools(self, **kw):
+ def tools(self, page=0, limit=200, **kw):
c.markdown_editor = W.markdown_editor
c.label_edit = W.label_edit
c.mount_delete = W.mount_delete
c.admin_modal = W.admin_modal
c.install_modal = W.install_modal
+ c.page_list = W.page_list
mounts = c.project.ordered_mounts()
+ total_mounts = len(mounts)
+ limit, page = h.paging_sanitizer(limit, page, total_mounts)
+ start = page * limit
return dict(
- mounts=mounts,
+ page=page,
+ limit=limit,
+ total_mounts=total_mounts,
+ mounts=mounts[start:start + limit],
installable_tools=AdminApp.installable_tools_for(c.project),
roles=M.ProjectRole.query.find(
dict(project_id=c.project.root_project._id)).sort('_id').all(),
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/Allura/allura/ext/admin/templates/project_tools.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/project_tools.html b/Allura/allura/ext/admin/templates/project_tools.html
index 56555d1..af777b0 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -142,6 +142,7 @@
{% endfor %}
</div>
</div>
+{{c.page_list.display(page=page, limit=limit, count=total_mounts)}}
<form id="mount_delete_form" style="display:none">
<div class="grid-13 warning_msg">Warning: This will destroy all data in this tool and is irreversible!</div>
<div class="grid-13"> </div>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 541ccbe..36112a0 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -56,6 +56,9 @@ from filesystem import File
log = logging.getLogger(__name__)
+# max sitemap entries per tool type
+SITEMAP_PER_TOOL_LIMIT = 10
+
class ProjectFile(File):
@@ -483,11 +486,18 @@ class Project(MappedClass, ActivityNode, ActivityObject):
result[award.granted_to_project_id].append(award)
return result
- def sitemap(self, excluded_tools=None):
+ def sitemap(self, excluded_tools=None, per_tool_limit=SITEMAP_PER_TOOL_LIMIT):
"""Return the project sitemap.
- :param list excluded_tools: tool names (AppConfig.tool_name) to
- exclude from sitemap
+ :param list excluded_tools:
+
+ Tool names (AppConfig.tool_name) to exclude from sitemap.
+
+ :param int per_tool_limit:
+
+ Max number of entries to include in the sitemap for a single tool
+ type. Use `None` to include all.
+
"""
from allura.app import SitemapEntry
entries = []
@@ -500,6 +510,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
delta_ordinal = i
max_ordinal = i
+ # Keep running count of entries per tool type
+ tool_counts = Counter({tool_name: 0 for tool_name in g.entry_points['tool']})
+
for sub in self.direct_subprojects:
ordinal = sub.ordinal + delta_ordinal
if ordinal > max_ordinal:
@@ -507,6 +520,15 @@ class Project(MappedClass, ActivityNode, ActivityObject):
entries.append({'ordinal': sub.ordinal + delta_ordinal,
'entry': SitemapEntry(sub.name, sub.url())})
for ac in self.app_configs + [a.config for a in new_tools]:
+ if per_tool_limit:
+ # We already have as many entries as we need for every tool type
+ if min(tool_counts.values()) >= per_tool_limit:
+ break
+
+ # We already have as many entries as we need for *this* tool type
+ if tool_counts.get(ac.tool_name, 0) >= per_tool_limit:
+ continue
+
if excluded_tools and ac.tool_name in excluded_tools:
continue
# Tool could've been uninstalled in the meantime
@@ -536,6 +558,7 @@ class Project(MappedClass, ActivityNode, ActivityObject):
if ordinal > max_ordinal:
max_ordinal = ordinal
entries.append({'ordinal': ordinal, 'entry': entry})
+ tool_counts.update({ac.tool_name: 1})
if self == self.neighborhood.neighborhood_project and h.has_access(self.neighborhood, 'admin'):
entries.append(
@@ -601,9 +624,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
# add tool url to list of urls that will match this nav
# entry
grouped_nav[tool_name].matching_urls.append(e.url)
- if len(grouped_nav[tool_name].children) < 10:
+ if len(grouped_nav[tool_name].children) < SITEMAP_PER_TOOL_LIMIT:
grouped_nav[tool_name].children.append(e)
- elif len(grouped_nav[tool_name].children) == 10:
+ elif len(grouped_nav[tool_name].children) == SITEMAP_PER_TOOL_LIMIT:
e.url = self.url() + '_list/' + tool_name
e.label = 'More...'
grouped_nav[tool_name].children.append(e)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/Allura/allura/templates/tool_list.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/tool_list.html b/Allura/allura/templates/tool_list.html
index 4dfe568..04ddcec 100644
--- a/Allura/allura/templates/tool_list.html
+++ b/Allura/allura/templates/tool_list.html
@@ -29,6 +29,7 @@
{% block header %}{{type}} tools{% endblock %}
{% block content %}
+{{c.page_list.display(page=page, limit=limit, count=total_entries)}}
<div>
<ul>
{% for e in entries %}
@@ -36,4 +37,5 @@
{% endfor %}
</ul>
</div>
+{{c.page_list.display(page=page, limit=limit, count=total_entries)}}
{% endblock %}