From 2f19529c922172007ff3894ad0e0fca0b3e33f5b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 13:48:07 -0500 Subject: Convert details sub-tempates to Jinja2 This is a start at improving performance of rendering the package details page, our most-visited and slowest page on the production website. The Django template system is not very efficient due to our heavy use of broken out templates and pulling of various attributes and such on related packages. Signed-off-by: Dan McGee --- packages/templatetags/package_extras.py | 5 ----- templates/packages/details.html | 10 +++++----- templates/packages/details_depend.html | 13 ------------- templates/packages/details_depend.html.jinja | 13 +++++++++++++ templates/packages/details_link.html.jinja | 1 + templates/packages/details_relatedto.html | 2 -- templates/packages/details_relatedto.html.jinja | 3 +++ templates/packages/details_requiredby.html | 8 -------- templates/packages/details_requiredby.html.jinja | 8 ++++++++ 9 files changed, 30 insertions(+), 33 deletions(-) delete mode 100644 templates/packages/details_depend.html create mode 100644 templates/packages/details_depend.html.jinja create mode 100644 templates/packages/details_link.html.jinja delete mode 100644 templates/packages/details_relatedto.html create mode 100644 templates/packages/details_relatedto.html.jinja delete mode 100644 templates/packages/details_requiredby.html create mode 100644 templates/packages/details_requiredby.html.jinja diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py index 3ce64748..2784546d 100644 --- a/packages/templatetags/package_extras.py +++ b/packages/templatetags/package_extras.py @@ -79,11 +79,6 @@ def pkg_details_link(pkg, link_title=None, honor_flagged=False): return link % (pkg.get_absolute_url(), pkg.pkgname, link_content) -@register.simple_tag -def multi_pkg_details(pkgs): - return ', '.join([pkg_details_link(pkg) for pkg in pkgs]) - - @register.simple_tag def maintainer_link(user): if user: diff --git a/templates/packages/details.html b/templates/packages/details.html index bfa2de16..c4c1f6b2 100644 --- a/templates/packages/details.html +++ b/templates/packages/details.html @@ -134,19 +134,19 @@

Versions Elsewhere

{% with pkg.provides.all as all_related %}{% if all_related %} Provides: - {% include "packages/details_relatedto.html" %} + {% include "packages/details_relatedto.html.jinja" %} {% endif %}{% endwith %} {% with pkg.replaces.all as all_related %}{% if all_related %} Replaces: - {% include "packages/details_relatedto.html" %} + {% include "packages/details_relatedto.html.jinja" %} {% endif %}{% endwith %} {% with pkg.conflicts.all as all_related %}{% if all_related %} Conflicts: - {% include "packages/details_relatedto.html" %} + {% include "packages/details_relatedto.html.jinja" %} {% endif %}{% endwith %} {% with pkg.reverse_conflicts as rev_conflicts %}{% if rev_conflicts %} @@ -205,7 +205,7 @@

Versions Elsewhere

Dependencies ({{deps|length}})

{% if deps %}{% endif %} {% endwith %} @@ -214,7 +214,7 @@

Required By ({{rqdby|length}})

{% if rqdby %}{% endif %} {% endwith %} diff --git a/templates/packages/details_depend.html b/templates/packages/details_depend.html deleted file mode 100644 index b89ffbfa..00000000 --- a/templates/packages/details_depend.html +++ /dev/null @@ -1,13 +0,0 @@ -{% load package_extras %}
  • {% ifequal depend.pkg None %} -{% if depend.providers %}{{ depend.dep.name }}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }} ({% multi_pkg_details depend.providers %}) -{% else %}{{ depend.dep.name }}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }} (virtual) -{% endif %}{% else %} -{% pkg_details_link depend.pkg %}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }} -{% if depend.pkg.repo.testing %} (testing) -{% endif %}{% if depend.pkg.repo.staging %} (staging) -{% endif %}{% endifequal %} -{% if depend.dep.deptype == 'O' %} (optional) -{% endif %}{% if depend.dep.deptype == 'M' %} (make) -{% endif %}{% if depend.dep.deptype == 'C' %} (check) -{% endif %}{% if depend.dep.description %} - {{ depend.dep.description }} -{% endif %}
  • diff --git a/templates/packages/details_depend.html.jinja b/templates/packages/details_depend.html.jinja new file mode 100644 index 00000000..404793b6 --- /dev/null +++ b/templates/packages/details_depend.html.jinja @@ -0,0 +1,13 @@ +{% import 'packages/details_link.html.jinja' as details %}
  • {% if depend.pkg == None %} +{% if depend.providers %}{{ depend.dep.name }}{{ depend.dep.comparison|default("") }}{{ depend.dep.version|default("") }} ({% for pkg in depend.providers %}{{ details.details_link(pkg) }}{% if not loop.last %}, {% endif %}{% endfor %}) +{% else %}{{ depend.dep.name }}{{ depend.dep.comparison|default("") }}{{ depend.dep.version|default("") }} (virtual) +{% endif %}{% else %} +{{ details.details_link(depend.pkg) }}{{ depend.dep.comparison|default("") }}{{ depend.dep.version|default("") }} +{% if depend.pkg.repo.testing %} (testing) +{% endif %}{% if depend.pkg.repo.staging %} (staging) +{% endif %}{% endif %} +{% if depend.dep.deptype == 'O' %} (optional) +{% endif %}{% if depend.dep.deptype == 'M' %} (make) +{% endif %}{% if depend.dep.deptype == 'C' %} (check) +{% endif %}{% if depend.dep.description %} - {{ depend.dep.description }} +{% endif %}
  • diff --git a/templates/packages/details_link.html.jinja b/templates/packages/details_link.html.jinja new file mode 100644 index 00000000..b7e75fe5 --- /dev/null +++ b/templates/packages/details_link.html.jinja @@ -0,0 +1 @@ +{% macro details_link(pkg) %}{{ pkg.pkgname }}{% endmacro %} diff --git a/templates/packages/details_relatedto.html b/templates/packages/details_relatedto.html deleted file mode 100644 index e14375d3..00000000 --- a/templates/packages/details_relatedto.html +++ /dev/null @@ -1,2 +0,0 @@ -{% load package_extras %}{% for related in all_related %}{% with related.get_best_satisfier as best_satisfier %}{% ifequal best_satisfier None %}{{ related.name }}{% else %}{% pkg_details_link best_satisfier %}{% endifequal %}{{ related.comparison|default:"" }}{{ related.version|default:"" }}{% if not forloop.last %}, {% endif %} -{% endwith %}{% endfor %} diff --git a/templates/packages/details_relatedto.html.jinja b/templates/packages/details_relatedto.html.jinja new file mode 100644 index 00000000..955fdd37 --- /dev/null +++ b/templates/packages/details_relatedto.html.jinja @@ -0,0 +1,3 @@ +{% import 'packages/details_link.html.jinja' as details %}{% for related in all_related %}{% with best_satisfier = related.get_best_satisfier() %} +{% if best_satisfier == None %}{{ related.name }}{% else %}{{ details.details_link(best_satisfier) }}{% endif %}{{ related.comparison|default("") }}{{ related.version|default("") }}{% if not loop.last %}, {% endif %} +{% endwith %}{% endfor %} diff --git a/templates/packages/details_requiredby.html b/templates/packages/details_requiredby.html deleted file mode 100644 index 504a322f..00000000 --- a/templates/packages/details_requiredby.html +++ /dev/null @@ -1,8 +0,0 @@ -{% load package_extras %}
  • {% pkg_details_link req.pkg %} -{% if req.name != pkg.pkgname %} (requires {{ req.name }}) -{% endif %}{% if req.pkg.repo.testing %} (testing) -{% endif %}{% if req.pkg.repo.staging %} (staging) -{% endif %}{% if req.deptype == 'O' %} (optional) -{% endif %}{% if req.deptype == 'M' %} (make) -{% endif %}{% if req.deptype == 'C' %} (check) -{% endif %}
  • diff --git a/templates/packages/details_requiredby.html.jinja b/templates/packages/details_requiredby.html.jinja new file mode 100644 index 00000000..b083a7fc --- /dev/null +++ b/templates/packages/details_requiredby.html.jinja @@ -0,0 +1,8 @@ +{% import 'packages/details_link.html.jinja' as details %}
  • {{ details.details_link(req.pkg) }} +{% if req.name != pkg.pkgname %} (requires {{ req.name }}) +{% endif %}{% if req.pkg.repo.testing %} (testing) +{% endif %}{% if req.pkg.repo.staging %} (staging) +{% endif %}{% if req.deptype == 'O' %} (optional) +{% endif %}{% if req.deptype == 'M' %} (make) +{% endif %}{% if req.deptype == 'C' %} (check) +{% endif %}
  • -- cgit v1.2.3-54-g00ecf