[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-blog] branch master updated: add paid article cache
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-blog] branch master updated: add paid article cache |
Date: |
Wed, 17 Jan 2018 15:37:59 +0100 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository blog.
The following commit(s) were added to refs/heads/master by this push:
new 6588044 add paid article cache
6588044 is described below
commit 6588044c841ee641fe9ad1e0d1c683629e2a00ed
Author: Florian Dold <address@hidden>
AuthorDate: Wed Jan 17 15:37:53 2018 +0100
add paid article cache
---
talerblog/blog/blog.py | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/talerblog/blog/blog.py b/talerblog/blog/blog.py
index 20320f6..c118872 100644
--- a/talerblog/blog/blog.py
+++ b/talerblog/blog/blog.py
@@ -28,6 +28,7 @@ import uuid
import base64
import requests
import flask
+from werkzeug.contrib.cache import SimpleCache
from talerblog.talerconfig import TalerConfig
from ..blog.content import ARTICLES, get_article_file, get_image_file
@@ -131,6 +132,28 @@ def refund(order_id):
flask.abort(500)
+def render_article(article_name):
+ article_info = ARTICLES.get(article_name)
+ if article_info is None:
+ flask.abort(500)
+ if data is not None:
+ if data in article_info.extra_files:
+ return flask.send_file(get_image_file(data))
+ return "permission denied", 403
+ # needed for refunds
+ order_id = flask.request.args.get("order_id")
+ return flask.render_template("templates/article_frame.html",
+ article_file=get_article_file(article_info),
+ article_name=article_name,
+ order_id=order_id)
+
+
+# Cache for paid articles (in the form <session_id>-<article_name>), so we
+# don't always have to ask the backend / DB, and so we don't have to store
+# variable-size cookies on the client.
+paid_articles_cache = SimpleCache()
+
+
@app.route("/essay/<article_name>")
@app.route("/essay/<article_name>/data/<data>")
def article(article_name, data=None):
@@ -145,6 +168,9 @@ def article(article_name, data=None):
if not session_id:
session_id = flask.session["uid"] = uuid.uuid4()
+ if paid_articles_cache.get(session_id + "-" + article_name):
+ return render_article(article_name)
+
if order_id and not session_sig:
# If there was an order_id but no session_sig, either the user played
# around with the URL or the wallet is old/broken.
@@ -180,17 +206,8 @@ def article(article_name, data=None):
article_name=article_name)
if pay_status.get("paid"):
- article_info = ARTICLES.get(article_name)
- if article_info is None:
- flask.abort(500)
- if data is not None:
- if data in article_info.extra_files:
- return flask.send_file(get_image_file(data))
- return "permission denied", 403
- return flask.render_template("templates/article_frame.html",
-
article_file=get_article_file(article_info),
- article_name=article_name,
- order_id=order_id)
+ paid_articles_cache.set(session_id + "-" + article_name, True)
+ return render_article(article_name)
# no pay_redirect but article not paid, this should never happen!
flask.abort(500)
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-blog] branch master updated: add paid article cache,
gnunet <=