marseys table is way way too large to use javascript for sorting, you would've known that if u had tested

pull/29/head
Aevann1 2022-11-28 06:59:35 +02:00
parent 2cdfb42c2f
commit fe0da05415
2 changed files with 50 additions and 35 deletions

View File

@ -26,15 +26,25 @@ def rdrama(id, title):
@app.get("/marseys") @app.get("/marseys")
@auth_required @auth_required
def marseys(v:User): def marseys(v:User):
marseys = get_marseys(g.db) if SITE == 'rdrama.net':
authors = get_accounts_dict([m.author_id for m in marseys], v=v, graceful=True, include_shadowbanned=False) marseys = g.db.query(Marsey, User).join(User, Marsey.author_id == User.id).filter(Marsey.submitter_id==None)
original = os.listdir("/asset_submissions/marseys/original") sort = request.values.get("sort", "usage")
for marsey in marseys: if sort == "usage":
marsey.user = authors.get(marsey.author_id) marseys = marseys.order_by(Marsey.count.desc(), User.username).all()
for x in IMAGE_FORMATS: elif sort == "added":
marseys = marseys.order_by(nullslast(Marsey.created_utc.desc()), User.username).all()
else: # implied sort == "author"
marseys = marseys.order_by(User.username, Marsey.count.desc()).all()
original = os.listdir("/asset_submissions/marseys/original")
for marsey, user in marseys:
for x in IMAGE_FORMATS:
if f'{marsey.name}.{x}' in original: if f'{marsey.name}.{x}' in original:
marsey.og = f'{marsey.name}.{x}' marsey.og = f'{marsey.name}.{x}'
break break
else:
marseys = g.db.query(Marsey).filter(Marsey.submitter_id==None).order_by(Marsey.count.desc())
return render_template("marseys.html", v=v, marseys=marseys) return render_template("marseys.html", v=v, marseys=marseys)
@app.get("/emojis") @app.get("/emojis")

View File

@ -5,41 +5,46 @@
<div class="overflow-x-auto mt-3"><table class="table table-striped mb-5"> <div class="overflow-x-auto mt-3"><table class="table table-striped mb-5">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th onclick="sort_table(0)">#</th> <th>#</th>
<th onclick="sort_table(1)">Name</th> <th>Name</th>
<th>Marsey</th> <th>Marsey</th>
<th onclick="sort_table(3)">Usage</th> <th>Usage</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %} {% if SITE == 'rdrama.net' %}
<th onclick="sort_table(4)">Author</th> <th><a href="?sort=author">Author</a></th>
{% endif %} <th><a href="?sort=added">Added on</a></th>
<th onclick="sort_table(5)">Added on</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %}
<th>Original File</th> <th>Original File</th>
{% endif %} {% endif %}
</tr> </tr>
</thead> </thead>
<tbody id="marseys-table"> <tbody id="marseys-table">
{% for marsey in marseys %} {% if SITE == 'rdrama.net' %}
<tr> {% for marsey, user in marseys %}
<td>{{loop.index}}</td> <tr>
<td data-sort-key="{{marsey.name}}">{{marsey.name}}</td> <td>{{loop.index}}</td>
<td><img class="marsey" loading="lazy" data-bs-toggle="tooltip" alt=":#{{marsey.name}}:" title=":{{marsey.name}}:" src="/e/{{marsey.name}}.webp"></td> <td>{{marsey.name}}</td>
<td>{{marsey.count}}</td> <td><img class="marsey" loading="lazy" data-bs-toggle="tooltip" alt=":#{{marsey.name}}:" title=":{{marsey.name}}:" src="/e/{{marsey.name}}.webp"></td>
{% if FEATURES['ASSET_SUBMISSIONS'] %} <td>{{marsey.count}}</td>
{% set user = marsey.user %} <td>{% include "user_in_table.html" %}</td>
<td data-sort-key="{{user.username.lower() if user else ''}}">{% include "user_in_table.html" %}</td> <td {% if marsey.created_utc != None %}data-time="{{marsey.created_utc}}"{% endif %}></td>
{% endif %} <td>
<td data-sort-key="{{marsey.created_utc or 0}}" {% if marsey.created_utc != None %}data-time="{{marsey.created_utc}}"{% endif %}></td> {% if marsey.og %}
{% if FEATURES['ASSET_SUBMISSIONS'] %} <a href="/asset_submissions/marseys/original/{{marsey.og}}">{{marsey.og}}</a>
<td> {% endif %}
{% if marsey.og %} </td>
<a href="/asset_submissions/marseys/original/{{marsey.og}}">{{marsey.og}}</a> </tr>
{% endif %} {% endfor %}
</td> {% else %}
{% endif %} {% for marsey in marseys %}
</tr> <tr>
{% endfor %} <td>{{loop.index}}</td>
<td>{{marsey.name}}</td>
<td><img class="marsey" loading="lazy" data-bs-toggle="tooltip" alt=":#{{marsey.name}}:" title=":{{marsey.name}}:" src="/e/{{marsey.name}}.webp"></td>
<td>{{marsey.count}}</td>
</tr>
{% endfor %}
{% endif %}
</tbody> </tbody>
</table> </table>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %} {% endblock %}