Cache the homepage template context.
This requires pillar-python-sdk c8eec9fa9d8a198df198538a38ca1ad2367bb3e6 or newer.
This commit is contained in:
@@ -84,8 +84,10 @@ class CloudExtension(PillarExtension):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pillar.api.service import signal_user_changed_role
|
from pillar.api.service import signal_user_changed_role
|
||||||
|
from . import routes
|
||||||
|
|
||||||
signal_user_changed_role.connect(self._user_changed_role)
|
signal_user_changed_role.connect(self._user_changed_role)
|
||||||
|
routes.setup_app(app)
|
||||||
|
|
||||||
def _user_changed_role(self, sender, user: dict):
|
def _user_changed_role(self, sender, user: dict):
|
||||||
from pillar.api import service
|
from pillar.api import service
|
||||||
|
@@ -28,6 +28,16 @@ def homepage():
|
|||||||
if current_user.is_anonymous:
|
if current_user.is_anonymous:
|
||||||
return redirect(url_for('cloud.welcome'))
|
return redirect(url_for('cloud.welcome'))
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'homepage.html',
|
||||||
|
api=system_util.pillar_api(),
|
||||||
|
**_homepage_context(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _homepage_context() -> dict:
|
||||||
|
"""Returns homepage template context variables."""
|
||||||
|
|
||||||
# Get latest blog posts
|
# Get latest blog posts
|
||||||
api = system_util.pillar_api()
|
api = system_util.pillar_api()
|
||||||
latest_posts = Node.all({
|
latest_posts = Node.all({
|
||||||
@@ -105,13 +115,11 @@ def homepage():
|
|||||||
for node in activity_stream:
|
for node in activity_stream:
|
||||||
node.url = url_for_node(node=node)
|
node.url = url_for_node(node=node)
|
||||||
|
|
||||||
return render_template(
|
return dict(
|
||||||
'homepage.html',
|
|
||||||
main_project=main_project,
|
main_project=main_project,
|
||||||
latest_posts=latest_posts._items,
|
latest_posts=latest_posts._items,
|
||||||
activity_stream=activity_stream,
|
activity_stream=activity_stream,
|
||||||
random_featured=random_featured,
|
random_featured=random_featured)
|
||||||
api=api)
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/login')
|
@blueprint.route('/login')
|
||||||
@@ -331,3 +339,9 @@ def billing():
|
|||||||
return render_template(
|
return render_template(
|
||||||
'users/settings/billing.html',
|
'users/settings/billing.html',
|
||||||
store_user=store_user, groups=groups, title='billing')
|
store_user=store_user, groups=groups, title='billing')
|
||||||
|
|
||||||
|
|
||||||
|
def setup_app(app):
|
||||||
|
global _homepage_context
|
||||||
|
cached = app.cache.cached(timeout=300)
|
||||||
|
_homepage_context = cached(_homepage_context)
|
||||||
|
Reference in New Issue
Block a user