From d5f8345581fd0838e38a72d2352146e561e1404a Mon Sep 17 00:00:00 2001
From: badbl0cks <4161747+badbl0cks@users.noreply.github.com>
Date: Fri, 28 Mar 2025 00:42:41 -0700
Subject: [PATCH] Rewrite how trade offer png's are generated to try to reduce
system resources. Only render the specific html code necessary and not the
entire trade offer details page.
---
Dockerfile | 4 +-
accounts/migrations/0001_initial.py | 7 +-
accounts/templatetags/gravatar.py | 5 +-
.../trades/trade_offer_confirm_create.html | 2 +-
.../templates/trades/trade_offer_detail.html | 6 +-
theme/templatetags/trade_offer_png.html | 146 ++++++++++++++++++
trades/migrations/0001_initial.py | 2 +-
trades/templatetags/trade_offer_tags.py | 54 ++++++-
trades/views.py | 98 ++++--------
9 files changed, 239 insertions(+), 85 deletions(-)
create mode 100644 theme/templatetags/trade_offer_png.html
diff --git a/Dockerfile b/Dockerfile
index 03993ae..0f9dcde 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -23,7 +23,7 @@ COPY .env.production /code/.env
ENV HOME=/code
# Install NPM & node.js
-RUN apt-get update && apt-get install -y nodejs npm xvfb libnss3 libnspr4 libasound2t64 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcairo2 libcups2 libdbus-1-3 libdrm2 libgbm1 libnspr4 libnss3 libpango-1.0-0 libx11-6 libxcb1 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 libcairo-gobject2 libdbus-glib-1-2 libfontconfig1 libfreetype6 libgdk-pixbuf-2.0-0 libgtk-3-0 libharfbuzz0b libpangocairo-1.0-0 libx11-xcb1 libxcb-shm0 libxcursor1 libxi6 libxrender1 libxtst6 libsoup-3.0-0 gstreamer1.0-libav gstreamer1.0-plugins-base gstreamer1.0-plugins-good libegl1 libenchant-2-2 libepoxy0 libevdev2 libgles2 libglx0 libgstreamer-gl1.0-0 libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 libgtk-4-1 libgudev-1.0-0 libharfbuzz-icu0 libhyphen0 libicu72 libjpeg62-turbo liblcms2-2 libmanette-0.2-0 libnotify4 libopengl0 libopenjp2-7 libopus0 libpng16-16 libproxy1v5 libsecret-1-0 libwayland-client0 libwayland-egl1 libwayland-server0 libwebp7 libwebpdemux2 libwoff1 libxml2 libxslt1.1 libatomic1 libevent-2.1-7 libavif16 xvfb fonts-noto-color-emoji fonts-unifont xfonts-scalable fonts-liberation fonts-ipafont-gothic fonts-wqy-zenhei fonts-tlwg-loma-otf fonts-freefont-ttf
+RUN apt-get update && apt-get install -y nodejs npm xvfb
RUN playwright install-deps && playwright install
@@ -37,4 +37,4 @@ RUN python manage.py collectstatic --noinput
#RUN python manage.py createcachetable django_cache
# Use gunicorn on port 8000
-CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "django_project.wsgi"]
+CMD ["gunicorn", "--bind", ":8000", "django_project.wsgi", "--timeout", "300"]
diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py
index da58fb7..142bab2 100644
--- a/accounts/migrations/0001_initial.py
+++ b/accounts/migrations/0001_initial.py
@@ -1,5 +1,6 @@
-# Generated by Django 5.1.2 on 2025-03-22 04:08
+# Generated by Django 5.1.2 on 2025-03-28 04:43
+import accounts.models
import django.contrib.auth.models
import django.contrib.auth.validators
import django.db.models.deletion
@@ -48,8 +49,8 @@ class Migration(migrations.Migration):
name='FriendCode',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('friend_code', models.CharField(max_length=19)),
- ('in_game_name', models.CharField(max_length=16)),
+ ('friend_code', models.CharField(max_length=19, validators=[accounts.models.validate_friend_code])),
+ ('in_game_name', models.CharField(max_length=14)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='friend_codes', to=settings.AUTH_USER_MODEL)),
diff --git a/accounts/templatetags/gravatar.py b/accounts/templatetags/gravatar.py
index 3aab3ba..c2005a0 100644
--- a/accounts/templatetags/gravatar.py
+++ b/accounts/templatetags/gravatar.py
@@ -24,6 +24,7 @@ def gravatar_url(email, size=20):
default = "retro"
email_hash = gravatar_hash(email)
params = urlencode({'d': default, 's': str(size)})
+ params = params.replace("&", "&")
return f"https://www.gravatar.com/avatar/{email_hash}?{params}"
@register.filter
@@ -44,7 +45,7 @@ def gravatar(email, size=20):
"""
url = gravatar_url(email, size)
# Return a safe HTML snippet with the image element
- html = f''
+ html = f'
'
return mark_safe(html)
@register.filter
@@ -55,7 +56,7 @@ def gravatar_no_hover(email, size=20):
"""
url = gravatar_url(email, size)
# Return a safe HTML snippet with the image element
- html = f'
'
+ html = f'
'
return mark_safe(html)
@register.filter
diff --git a/theme/templates/trades/trade_offer_confirm_create.html b/theme/templates/trades/trade_offer_confirm_create.html
index 26cbac2..1a6827d 100644
--- a/theme/templates/trades/trade_offer_confirm_create.html
+++ b/theme/templates/trades/trade_offer_confirm_create.html
@@ -17,7 +17,7 @@
{% endfor %}
{% endfor %}
- {% render_trade_offer dummy_trade_offer False False True %}
+ {% render_trade_offer dummy_trade_offer True %}