diff options
author | rubenwardy <rw@rubenwardy.com> | 2020-07-16 13:52:18 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2020-07-16 13:52:18 +0100 |
commit | 208a47b41d2d81f95a47c2e59c69310aa3486426 (patch) | |
tree | c053a5c2d5b2c42650eb50f9a9e774789e16ab9f | |
parent | 7fb2f3170c067e7869bfb19f29da5f4d41762f34 (diff) | |
download | cheatdb-208a47b41d2d81f95a47c2e59c69310aa3486426.tar.xz |
Fix tag views redis cache
-rw-r--r-- | app/blueprints/packages/packages.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index 8cb9b62..bacbbe1 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -52,18 +52,20 @@ def list_all(): joinedload(Package.media_license), \ subqueryload(Package.tags)) - edited = False - for tag in qb.tags: - edited = True - key = "tag-" + tag.name - if not has_key(key): - set_key(key, "true") - Tag.query.filter_by(id=tag.id).update({ - "views": Tag.views + 1 - }) - - if edited: - db.session.commit() + ip = request.headers.get("X-Forwarded-For") or request.remote_addr + if ip is not None: + edited = False + for tag in qb.tags: + edited = True + key = "tag/{}/{}".format(ip, tag.name) + if not has_key(key): + set_key(key, "true") + Tag.query.filter_by(id=tag.id).update({ + "views": Tag.views + 1 + }) + + if edited: + db.session.commit() if qb.lucky: package = query.first() |