make leaderboard not take forever to load by removing the winnings tables

master
Aevann1 2022-09-16 22:05:28 +02:00
parent 938db9428d
commit dad0018698
2 changed files with 14 additions and 77 deletions

View File

@ -585,20 +585,20 @@ def leaderboard(v):
pos13 = (pos13+1, users13[pos13][1]) pos13 = (pos13+1, users13[pos13][1])
except: pos13 = (len(users13)+1, 0) except: pos13 = (len(users13)+1, 0)
winnings_sq = g.db.query(Casino_Game.user_id, func.sum(Casino_Game.winnings)).group_by(Casino_Game.user_id).subquery() # winnings_sq = g.db.query(Casino_Game.user_id, func.sum(Casino_Game.winnings)).group_by(Casino_Game.user_id).subquery()
users14 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.desc()).limit(25).all() # users14 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.desc()).limit(25).all()
if v in users14: # if v in users14:
pos14 = None # pos14 = None
else: # else:
sq = g.db.query(User.id, func.rank().over(order_by=winnings_sq.c.sum.desc()).label("rank")).join(winnings_sq, winnings_sq.c.user_id == User.id).subquery() # sq = g.db.query(User.id, func.rank().over(order_by=winnings_sq.c.sum.desc()).label("rank")).join(winnings_sq, winnings_sq.c.user_id == User.id).subquery()
pos14 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] # pos14 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
users15 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.asc()).limit(25).all() # users15 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.asc()).limit(25).all()
if v in users15: # if v in users15:
pos15 = None # pos15 = None
else: # else:
sq = g.db.query(User.id, func.rank().over(order_by=winnings_sq.c.sum.asc()).label("rank")).join(winnings_sq, winnings_sq.c.user_id == User.id).subquery() # sq = g.db.query(User.id, func.rank().over(order_by=winnings_sq.c.sum.asc()).label("rank")).join(winnings_sq, winnings_sq.c.user_id == User.id).subquery()
pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] # pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("count")).group_by(UserBlock.target_id).subquery() sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("count")).group_by(UserBlock.target_id).subquery()
users16 = g.db.query(User, sq.c.count).join(User, User.id == sq.c.target_id).order_by(sq.c.count.desc()) users16 = g.db.query(User, sq.c.count).join(User, User.id == sq.c.target_id).order_by(sq.c.count.desc())
@ -623,7 +623,7 @@ def leaderboard(v):
users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5, users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5,
users7=users7, pos7=pos7, users9=users9_accs, pos9=pos9, users7=users7, pos7=pos7, users9=users9_accs, pos9=pos9,
users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12,
users13=users13_accs, pos13=pos13, users14=users14, pos14=pos14, users15=users15, pos15=pos15, users13=users13_accs, pos13=pos13, pos15=pos15,
users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18) users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18)
@app.get("/<id>/css") @app.get("/<id>/css")

View File

@ -16,8 +16,6 @@
<a href="#leaderboard-badges">Badges</a> &bull; <a href="#leaderboard-badges">Badges</a> &bull;
{% if users12 %}<a href="#leaderboard-marseys">Marseys</a> &bull; {% endif %} {% if users12 %}<a href="#leaderboard-marseys">Marseys</a> &bull; {% endif %}
{% if users13 %}<a href="#leaderboard-upgiven">Upvotes Given</a> &bull; {% endif %} {% if users13 %}<a href="#leaderboard-upgiven">Upvotes Given</a> &bull; {% endif %}
<a href="#leaderboard-winnings">Winnings</a> &bull;
<a href="#leaderboard-losses">Losses</a> &bull;
<a href="#leaderboard-blocked">Blocked</a> &bull; <a href="#leaderboard-blocked">Blocked</a> &bull;
<a href="#leaderboard-owned-hats">Owned Hats</a> &bull; <a href="#leaderboard-owned-hats">Owned Hats</a> &bull;
<a href="#leaderboard-designed-hats">Designed Hats</a> <a href="#leaderboard-designed-hats">Designed Hats</a>
@ -372,67 +370,6 @@
</table> </table>
{% endif %} {% endif %}
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-winnings">Top 25 by winnings</a></h5>
<div class="overflow-x-auto"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>#</th>
<th>Name</th>
<th>Winnings</th>
</tr>
</thead>
{% for user in users14 %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td>{% include "user_in_table.html" %}</td>
<td>{{"{:,}".format(user.winnings)}}</td>
</tr>
{% endfor %}
{% if pos14 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos14}}</td>
<td>
{% with user=v %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>{{"{:,}".format(v.winnings)}}</td>
</tr>
{% endif %}
</table>
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-losses">Bottom 25 by winnings</a></h5>
<div class="overflow-x-auto"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>#</th>
<th>Name</th>
<th>Winnings</th>
</tr>
</thead>
{% for user in users15 %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td>{% include "user_in_table.html" %}</td>
<td>{{"{:,}".format(user.winnings)}}</td>
</tr>
{% endfor %}
{% if pos15 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos15}}</td>
<td>
{% with user=v %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>{{"{:,}".format(v.winnings)}}</td>
</tr>
{% endif %}
</table>
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-blocked">Top 25 Most Blocked</a></h5> <h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-blocked">Top 25 Most Blocked</a></h5>
<div class="overflow-x-auto"><table class="table table-striped mb-5"> <div class="overflow-x-auto"><table class="table table-striped mb-5">