From dced6d53bfbca1f6284cdaa9145a67cd51e56dab Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 5 May 2021 02:00:36 -0700 Subject: [PATCH] adjustments to top posters --- suchwow/routes/leaderboard.py | 31 +++++++++++++++++------------- suchwow/templates/leaderboard.html | 6 ++---- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/suchwow/routes/leaderboard.py b/suchwow/routes/leaderboard.py index dbea893..dc6ec9e 100644 --- a/suchwow/routes/leaderboard.py +++ b/suchwow/routes/leaderboard.py @@ -13,19 +13,24 @@ bp = Blueprint("leaderboard", "leaderboard") @bp.route("/leaderboards/top_posters") def top_posters(): top_posters = {} - posts = Post.select().where(Post.approved==True) - for post in posts: - transfers = [] - incoming = wownero.Wallet().incoming_transfers(post.account_index) - if "transfers" in incoming: - for xfer in incoming["transfers"]: - transfers.append(wownero.from_atomic(xfer["amount"])) - total = sum(transfers) - if post.submitter not in top_posters: - top_posters[post.submitter] = {"amount": 0, "posts": []} - - top_posters[post.submitter]["amount"] += float(total) - top_posters[post.submitter]["posts"].append(post) + posts = rw_cache('top_posters') + if not posts: + posts = Post.select().where(Post.approved==True) + for post in posts: + transfers = [] + incoming = wownero.Wallet().incoming_transfers(post.account_index) + if "transfers" in incoming: + for xfer in incoming["transfers"]: + transfers.append(wownero.from_atomic(xfer["amount"])) + total = sum(transfers) + if post.submitter not in top_posters: + top_posters[post.submitter] = {"amount": 0, "posts": []} + + top_posters[post.submitter]["amount"] += float(total) + top_posters[post.submitter]["posts"].append(post) + rw_cache('top_posters', top_posters) + else: + top_posters = posts return render_template("leaderboard.html", posters=top_posters) diff --git a/suchwow/templates/leaderboard.html b/suchwow/templates/leaderboard.html index 917f61e..f6ba378 100644 --- a/suchwow/templates/leaderboard.html +++ b/suchwow/templates/leaderboard.html @@ -2,11 +2,9 @@ {% block content %} -
+
-
-

{% block title %}Top Posters{% endblock %}

-
+

Top Posters

{% if posters %}