[MediaWiki-commits] [Gerrit] operations/puppet[production]: Puppet Panel: Speed up role formatting

2016-09-15 Thread Andrew Bogott (Code Review)
Andrew Bogott has submitted this change and it was merged.

Change subject: Puppet Panel:  Speed up role formatting
..


Puppet Panel:  Speed up role formatting

These format functions are really the responsiblity of the view,
but moving them into the model (puppet_roles.py) allows us to
cache the formatted role properties.  This should save us a tiny
bit of render time.

Bug: T91990
Change-Id: I1af176860e6c0ac42012f2a0bd8c349f19c74e11
---
M modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py
M modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py
2 files changed, 23 insertions(+), 40 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py 
b/modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py
index 5a64a3e..69bf466 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py
@@ -18,6 +18,9 @@
 
 from django.conf import settings
 from django.core.cache import cache
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
+from django.utils.translation import ugettext_lazy as _
 
 logging.basicConfig()
 LOG = logging.getLogger(__name__)
@@ -27,18 +30,22 @@
 #  for our Horizon table-of-roles UI
 class PuppetClass():
 name = None
+html_name = ""
 docs = ""
 applied = False
 params = []
+formatted_params = ""
 raw_params = {}
 filter_tags = []
 instance = None
 
 def __init__(self, name):
 self.name = name
-self.docs = ""
+self.html_name = ""
+self.docs = _('(No docs available)')
 self.applied = False
 self.params = []
+self.formatted_params = ""
 self.raw_params = {}
 self.filter_tags = []
 self.instance = None
@@ -51,6 +58,12 @@
 def mark_applied(self, paramdict):
 self.applied = True
 self.params = paramdict
+if paramdict:
+keysanddefaults = []
+for param in self.params.items():
+keysanddefaults.append("%s: %s" % param)
+self.formatted_params = ";\n".join(keysanddefaults)
+
 return self
 
 
@@ -99,6 +112,13 @@
 newdoc += "%s\n" % line
 obj.docs = newdoc
 
+simplename = obj.name.split('role::')[1]
+html = '%s ' % (
+escape(simplename),
+escape(obj.docs)
+)
+obj.html_name = mark_safe(html)
+
 roles.append(obj)
 
 cache.set(key, roles, 300)
diff --git a/modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py 
b/modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py
index ab6310b..38f1d0a 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py
@@ -19,43 +19,10 @@
 from django.core import urlresolvers
 from django.utils.translation import ugettext_lazy as _
 
-from django.utils.html import escape
-from django.utils.safestring import mark_safe
-
 from horizon import tables
-
-import puppet_roles
 
 logging.basicConfig()
 LOG = logging.getLogger(__name__)
-
-
-def get_formatted_name(classrecord):
-name = classrecord.name.split('role::')[1]
-title = get_docs_for_class(name)
-html = '%s ' % (
-escape(name),
-escape(title)
-)
-return mark_safe(html)
-
-
-def get_formatted_params(classrecord):
-if classrecord.params:
-keysanddefaults = []
-for param in classrecord.params.items():
-keysanddefaults.append("%s: %s" % param)
-return(";\n".join(keysanddefaults))
-
-
-def get_docs_for_class(classname):
-allroles = puppet_roles.available_roles()
-for role in allroles:
-if role.name.split('role::')[1] == classname:
-if role.docs:
-return role.docs
-break
-return _('(No docs available)')
 
 
 class RemoveRole(tables.LinkAction):
@@ -142,9 +109,9 @@
 
 class PuppetTable(tables.DataTable):
 applied = tables.Column('applied', verbose_name=_('Applied'), status=True)
-name = tables.Column(get_formatted_name,
+name = tables.Column('html_name',
  verbose_name=_('Name'))
-params = tables.Column(get_formatted_params,
+params = tables.Column('formatted_params',
verbose_name=_('Parameters'),
sortable=False)
 instance = tables.Column('instance',
@@ -167,7 +134,3 @@
 
 def get_object_id(self, datum):
 return datum.name
-
-def render_to_response(self, context, **response_kwargs):
-LOG.warn("render_to_response 2: %s" %
- self.request.GET.get('format', 'html'))

-- 
To 

[MediaWiki-commits] [Gerrit] operations/puppet[production]: Puppet Panel: Speed up role formatting

2016-09-15 Thread Andrew Bogott (Code Review)
Andrew Bogott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311057

Change subject: Puppet Panel:  Speed up role formatting
..

Puppet Panel:  Speed up role formatting

These format functions are really the responsiblity of the view,
but moving them into the model (puppet_roles.py) allows us to
cache the formatted role properties.  This should save us a tiny
bit of render time.

Bug: T91990
Change-Id: I1af176860e6c0ac42012f2a0bd8c349f19c74e11
---
M modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py
M modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py
2 files changed, 21 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/57/311057/1

diff --git a/modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py 
b/modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py
index 12e41fb..69bf466 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/puppet_roles.py
@@ -18,6 +18,8 @@
 
 from django.conf import settings
 from django.core.cache import cache
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
 from django.utils.translation import ugettext_lazy as _
 
 logging.basicConfig()
@@ -28,18 +30,22 @@
 #  for our Horizon table-of-roles UI
 class PuppetClass():
 name = None
+html_name = ""
 docs = ""
 applied = False
 params = []
+formatted_params = ""
 raw_params = {}
 filter_tags = []
 instance = None
 
 def __init__(self, name):
 self.name = name
+self.html_name = ""
 self.docs = _('(No docs available)')
 self.applied = False
 self.params = []
+self.formatted_params = ""
 self.raw_params = {}
 self.filter_tags = []
 self.instance = None
@@ -52,6 +58,12 @@
 def mark_applied(self, paramdict):
 self.applied = True
 self.params = paramdict
+if paramdict:
+keysanddefaults = []
+for param in self.params.items():
+keysanddefaults.append("%s: %s" % param)
+self.formatted_params = ";\n".join(keysanddefaults)
+
 return self
 
 
@@ -100,6 +112,13 @@
 newdoc += "%s\n" % line
 obj.docs = newdoc
 
+simplename = obj.name.split('role::')[1]
+html = '%s ' % (
+escape(simplename),
+escape(obj.docs)
+)
+obj.html_name = mark_safe(html)
+
 roles.append(obj)
 
 cache.set(key, roles, 300)
diff --git a/modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py 
b/modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py
index fab2e6e..38f1d0a 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/puppet_tables.py
@@ -19,31 +19,10 @@
 from django.core import urlresolvers
 from django.utils.translation import ugettext_lazy as _
 
-from django.utils.html import escape
-from django.utils.safestring import mark_safe
-
 from horizon import tables
 
 logging.basicConfig()
 LOG = logging.getLogger(__name__)
-
-
-def get_formatted_name(classrecord):
-name = classrecord.name.split('role::')[1]
-title = classrecord.docs
-html = '%s ' % (
-escape(name),
-escape(title)
-)
-return mark_safe(html)
-
-
-def get_formatted_params(classrecord):
-if classrecord.params:
-keysanddefaults = []
-for param in classrecord.params.items():
-keysanddefaults.append("%s: %s" % param)
-return(";\n".join(keysanddefaults))
 
 
 class RemoveRole(tables.LinkAction):
@@ -130,9 +109,9 @@
 
 class PuppetTable(tables.DataTable):
 applied = tables.Column('applied', verbose_name=_('Applied'), status=True)
-name = tables.Column(get_formatted_name,
+name = tables.Column('html_name',
  verbose_name=_('Name'))
-params = tables.Column(get_formatted_params,
+params = tables.Column('formatted_params',
verbose_name=_('Parameters'),
sortable=False)
 instance = tables.Column('instance',
@@ -155,7 +134,3 @@
 
 def get_object_id(self, datum):
 return datum.name
-
-def render_to_response(self, context, **response_kwargs):
-LOG.warn("render_to_response 2: %s" %
- self.request.GET.get('format', 'html'))

-- 
To view, visit https://gerrit.wikimedia.org/r/311057
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1af176860e6c0ac42012f2a0bd8c349f19c74e11
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Andrew Bogott