dont cache notification count in /leaderboard to prevent user confusion

pull/200/head
Aevann 2023-09-05 22:10:49 +03:00
parent b7017e3e74
commit 78ba2f4a62
3 changed files with 72 additions and 70 deletions

View File

@ -474,12 +474,8 @@ def transfer_coins(v, username):
def transfer_bux(v, username):
return transfer_currency(v, username, 'marseybux', False)
@app.get("/leaderboard")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
@cache.memoize()
def leaderboard(v):
def leaderboard_cached(v):
users = g.db.query(User)
coins = Leaderboard("Coins", "coins", "coins", "Coins", None, Leaderboard.get_simple_lb, User.coins, v, lambda u:u.coins, users)
@ -510,7 +506,14 @@ def leaderboard(v):
leaderboards.append(Leaderboard("Casino winnings (top)", "casino winnings", "casino-winnings-top", "Casino Winnings", None, Leaderboard.get_winnings_lb, CasinoGame.winnings, v, None, None))
leaderboards.append(Leaderboard("Casino winnings (bottom)", "casino winnings", "casino-winnings-bottom", "Casino Winnings", None, Leaderboard.get_winnings_lb, CasinoGame.winnings, v, None, None, 25, False))
return render_template("leaderboard.html", v=v, leaderboards=leaderboards)
return render_template("leaderboard_cached.html", v=v, leaderboards=leaderboards)
@app.get("/leaderboard")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def leaderboard(v):
return render_template("leaderboard.html", v=v, leaderboard_cached=leaderboard_cached(v))
@app.get("/<int:id>/css")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)

View File

@ -1,68 +1,5 @@
{% extends "settings2.html" %}
{% block pagetitle %}Leaderboard{% endblock %}
{% block content %}
<header id="leaderboard-header" class="container text-center pb-3">
<img loading="lazy" id="leaderboard-banner" alt="leaderboard banner" src="{{SITE_FULL_IMAGES}}/i/leaderboard.webp">
</header>
<div class="mt-2" id="leaderboard-contents" style="text-align: center; margin-bottom: 1.5rem; font-size: 1.2rem;">
{% for lb in leaderboards %}
{% if lb %}
<a href="#leaderboard-{{lb.html_id}}">{{lb.header_name}}</a>{% if not loop.last %} &bull;{% endif %}
{% endif %}
{% endfor %}
</div>
{% macro format_user_in_table(user, style, position_no, value, user_relative_url) %}
{% set value = value | int %}
<tr {{style | safe}}>
<td>{{position_no}}</td>
<td>{% include "user_in_table.html" %}</td>
{% if user_relative_url is not none %}
<td><a href="/@{{user.username}}/{{user_relative_url}}">{{"{:,}".format(value)}}</a></td>
{% else %}
<td>{{"{:,}".format(value)}}</td>
{% endif %}
</tr>
{% endmacro %}
{% macro leaderboard_table(lb) %}
<h5 class="font-weight-bolder text-center pt-2 pb-3"><span id="leaderboard-{{lb.html_id}}">{% if lb.desc %}Top{% else %}Bottom{% endif %} {{lb.limit}} {% if lb.table_header_name != 'most blocked' %}by{% endif %} {{lb.table_header_name}}</span></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>{{lb.table_column_name}}</th>
</tr>
</thead>
<tbody>
{% for user in lb.all_users %}
{% set user2 = lb.user_func(user) %}
{% if v.id == user2.id %}
{% set style="class=\"self\"" %}
{% endif %}
{{format_user_in_table(user2, style, loop.index, lb.value_func(user), lb.user_relative_url)}}
{% endfor %}
{% if lb.v_position and not lb.v_appears_in_ranking %}
{{format_user_in_table(v, "style=\"border-top:2px solid var(--primary)\"", lb.v_position, lb.v_value, lb.user_relative_url)}}
{% endif %}
</tbody>
</table>
</div>
{% endmacro %}
{% for lb in leaderboards %}
{% if lb %}
{{leaderboard_table(lb)}}
{% endif %}
{% endfor %}
<a id="leader--top-btn" href="#leaderboard-contents"
style="position: fixed; bottom: 5rem; right: 2rem; font-size: 3rem;">
<i class="fas fa-arrow-alt-circle-up"></i>
</a>
{{leaderboard_cached | safe}}
{% endblock %}

View File

@ -0,0 +1,62 @@
<header id="leaderboard-header" class="container text-center pb-3">
<img loading="lazy" id="leaderboard-banner" alt="leaderboard banner" src="{{SITE_FULL_IMAGES}}/i/leaderboard.webp">
</header>
<div class="mt-2" id="leaderboard-contents" style="text-align: center; margin-bottom: 1.5rem; font-size: 1.2rem;">
{% for lb in leaderboards %}
{% if lb %}
<a href="#leaderboard-{{lb.html_id}}">{{lb.header_name}}</a>{% if not loop.last %} &bull;{% endif %}
{% endif %}
{% endfor %}
</div>
{% macro format_user_in_table(user, style, position_no, value, user_relative_url) %}
{% set value = value | int %}
<tr {{style | safe}}>
<td>{{position_no}}</td>
<td>{% include "user_in_table.html" %}</td>
{% if user_relative_url is not none %}
<td><a href="/@{{user.username}}/{{user_relative_url}}">{{"{:,}".format(value)}}</a></td>
{% else %}
<td>{{"{:,}".format(value)}}</td>
{% endif %}
</tr>
{% endmacro %}
{% macro leaderboard_table(lb) %}
<h5 class="font-weight-bolder text-center pt-2 pb-3"><span id="leaderboard-{{lb.html_id}}">{% if lb.desc %}Top{% else %}Bottom{% endif %} {{lb.limit}} {% if lb.table_header_name != 'most blocked' %}by{% endif %} {{lb.table_header_name}}</span></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>{{lb.table_column_name}}</th>
</tr>
</thead>
<tbody>
{% for user in lb.all_users %}
{% set user2 = lb.user_func(user) %}
{% if v.id == user2.id %}
{% set style="class=\"self\"" %}
{% endif %}
{{format_user_in_table(user2, style, loop.index, lb.value_func(user), lb.user_relative_url)}}
{% endfor %}
{% if lb.v_position and not lb.v_appears_in_ranking %}
{{format_user_in_table(v, "style=\"border-top:2px solid var(--primary)\"", lb.v_position, lb.v_value, lb.user_relative_url)}}
{% endif %}
</tbody>
</table>
</div>
{% endmacro %}
{% for lb in leaderboards %}
{% if lb %}
{{leaderboard_table(lb)}}
{% endif %}
{% endfor %}
<a id="leader--top-btn" href="#leaderboard-contents"
style="position: fixed; bottom: 5rem; right: 2rem; font-size: 3rem;">
<i class="fas fa-arrow-alt-circle-up"></i>
</a>