Leaderboard: fix user join for ea48c46b0f.

After ea48c46b0f adds the leaderboard table for most blocked user,
it appeared that the user profile links did not appear correctly.
As such, it was necessary to join on the appropriate information.
This has been (mostly) resolved, excluding the removal of profile
picture because profile_url has logic in Python.

If someone knows SQLAlchemy better than I do, please redo this and
add the profile pictures back into the template. However, I got tired
of fighting with the ORM when I already knew the damn query.
remotes/1693045480750635534/spooky-22
Snakes 2022-05-25 06:09:13 -04:00
parent ea48c46b0f
commit 42d810a5e7
2 changed files with 8 additions and 5 deletions

View File

@ -10,6 +10,7 @@ from files.mail import *
from flask import *
from files.__main__ import app, limiter, db_session
import sqlalchemy
from sqlalchemy import text
from pusher_push_notifications import PushNotifications
from collections import Counter
import gevent
@ -538,8 +539,10 @@ def leaderboard(v):
sq = g.db.query(User.id, func.rank().over(order_by=User.winnings).label("rank")).subquery()
pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
usersBlk = g.db.query(UserBlock.target_id, func.count().label('blocked_by')) \
.group_by(UserBlock.target_id).order_by(sqlalchemy.desc('blocked_by')).limit(25).all()
usersBlk = g.db.execute(text('SELECT \
blk.target_id, blk.n, users.username, users.namecolor, users.patron \
FROM (SELECT target_id, count(target_id) AS n FROM userblocks GROUP BY target_id) AS blk \
JOIN users ON users.id = blk.target_id ORDER BY blk.n DESC LIMIT 25'))
return render_template("leaderboard.html", v=v, users1=users1, pos1=pos1, users2=users2, pos2=pos2,
users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5,

View File

@ -510,10 +510,10 @@
</tr>
</thead>
{% for user in usersBlk %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<tr {% if v.id == user.target_id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}};font-weight:bold" href="/@{{user.username}}"><img loading="lazy" src="{{user.profile_url}}" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}}"{% endif %}>{{user.username}}</span></a></td>
<td>{{user.blocked_by}}</td>
<td><a style="color:#{{user.namecolor}};font-weight:bold" href="/@{{user.username}}"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}}"{% endif %}>{{user.username}}</span></a></td>
<td>{{user.n}}</td>
</tr>
{% endfor %}
</table>