Private
Public Access
1
0

chg: dev: add RecentBattle entity that is a Materialized View to speed up the view - and further refactor on ProfileController #8

This commit is contained in:
2026-04-20 21:08:15 +02:00
parent 6a5ba84b5e
commit 2ec37a802b
7 changed files with 341 additions and 35 deletions

View File

@@ -127,32 +127,16 @@
</div>
<div class="profile-games" data-batch-size="5">
{% for game in recent %}
{% set is_red = game.red and game.red.id == app.user.id %}
{% set is_red = game.isRed %}
{% set my_points = is_red ? game.redPoints : game.bluePoints %}
{% set opp_points = is_red ? game.bluePoints : game.redPoints %}
{% set opp = is_red ? game.blue : game.red %}
{% set opp_anon = is_red ? game.blueAnon : game.redAnon %}
{% set opp_name = is_red ? game.blueName : game.redName %}
{% set result = game.result %}
{% set result = 'draw' %}
{% set is_finished = false %}
{% set is_anonymous = not opp and opp_anon %}
{% if game.resign == (is_red ? 'red' : 'blue') %}
{% set result = 'loss' %}
{% set is_finished = true %}
{% elseif game.resign == (is_red ? 'blue' : 'red') %}
{% set result = 'win' %}
{% set is_finished = true %}
{% elseif my_points is not null and opp_points is not null %}
{% if my_points > opp_points %}
{% set result = 'win' %}
{% set is_finished = (my_points > 25 or opp_points > 25) %}
{% elseif my_points < opp_points %}
{% set result = 'loss' %}
{% set is_finished = (my_points > 25 or opp_points > 25) %}
{% else %}
{% set is_finished = (my_points > 25 or opp_points > 25) %}
{% endif %}
{% endif %}
{% set is_finished = game.resign is not null
or (my_points is not null and opp_points is not null
and (my_points > 25 or opp_points > 25)) %}
{% set is_anonymous = game.oppIsGuest %}
<div class="profile-game profile-game--{{ result }}{% if not is_finished and not is_anonymous %} profile-game--ongoing{% elseif is_anonymous %} profile-game--abandoned{% endif %}{% if loop.index0 >= 5 %} profile-game--hidden{% endif %}" data-game-index="{{ loop.index0 }}">
<span class="profile-game__badge">
@@ -168,15 +152,7 @@
{{ my_points ?? '—' }} : {{ opp_points ?? '—' }}
</span>
<span class="profile-game__vs">vs</span>
<span class="profile-game__opponent">
{% if opp %}
{{ opp.username }}
{% elseif opp_anon %}
{{ opp_anon.userName }}
{% else %}
Guest
{% endif %}
</span>
<span class="profile-game__opponent">{{ opp_name }}</span>
<span class="profile-game__color">
<i class="fas fa-circle" style="color: {{ is_red ? '#c0392b' : '#2980b9' }}"></i>
</span>