mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-01-06 15:44:22 +01:00
Cache pages (#380)
* Cache static pages so that we don't need to hit the database for them as often * Closes #378
This commit is contained in:
@@ -43,11 +43,15 @@ def admin_pages_view(route):
|
||||
page.html = html
|
||||
db.session.commit()
|
||||
db.session.close()
|
||||
with app.app_context():
|
||||
cache.clear()
|
||||
return redirect(url_for('admin_pages.admin_pages_view'))
|
||||
page = Pages(route, html)
|
||||
db.session.add(page)
|
||||
db.session.commit()
|
||||
db.session.close()
|
||||
with app.app_context():
|
||||
cache.clear()
|
||||
return redirect(url_for('admin_pages.admin_pages_view'))
|
||||
pages = Pages.query.all()
|
||||
return render_template('admin/pages.html', routes=pages, css=utils.get_config('css'))
|
||||
@@ -82,4 +86,6 @@ def delete_page(pageroute):
|
||||
db.session.delete(page)
|
||||
db.session.commit()
|
||||
db.session.close()
|
||||
with app.app_context():
|
||||
cache.clear()
|
||||
return '1'
|
||||
|
||||
@@ -193,6 +193,11 @@ def pages():
|
||||
return pages
|
||||
|
||||
|
||||
@cache.memoize()
|
||||
def get_page(template):
|
||||
return Pages.query.filter_by(route=template).first()
|
||||
|
||||
|
||||
def authed():
|
||||
return bool(session.get('id', False))
|
||||
|
||||
|
||||
@@ -111,7 +111,9 @@ def static_html(template):
|
||||
try:
|
||||
return render_template('%s.html' % template)
|
||||
except TemplateNotFound:
|
||||
page = Pages.query.filter_by(route=template).first_or_404()
|
||||
page = utils.get_page(template)
|
||||
if page is None:
|
||||
abort(404)
|
||||
return render_template('page.html', content=markdown(page.html))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user