Skip to content

Commit 0026fc0

Browse files
perf(coordinator): remove avatar generator #1242
2 parents d7eebb1 + 7558ef4 commit 0026fc0

File tree

5 files changed

+6
-51
lines changed

5 files changed

+6
-51
lines changed

api/admin.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@
2121
class RobotInline(admin.StackedInline):
2222
model = Robot
2323
can_delete = False
24-
fields = ("avatar_tag",)
25-
readonly_fields = ["avatar_tag"]
2624
show_change_link = True
2725

2826

29-
# extended users with avatars
3027
@admin.register(User)
3128
class EUserAdmin(AdminChangeLinksMixin, UserAdmin):
3229
inlines = [RobotInline]
3330
list_display = (
34-
"avatar_tag",
3531
"id",
3632
"robot_link",
3733
"username",
@@ -43,25 +39,18 @@ class EUserAdmin(AdminChangeLinksMixin, UserAdmin):
4339
change_links = ("robot",)
4440
ordering = ("-id",)
4541

46-
def avatar_tag(self, obj):
47-
return obj.robot.avatar_tag()
4842

49-
50-
# extended tokens with raw id fields and avatars
43+
# extended tokens with raw id fields
5144
@admin.register(TokenProxy)
5245
class ETokenAdmin(AdminChangeLinksMixin, TokenAdmin):
5346
raw_id_fields = ["user"]
5447
list_display = (
55-
"avatar_tag",
5648
"key",
5749
"user_link",
5850
)
5951
list_display_links = ("key",)
6052
change_links = ("user",)
6153

62-
def avatar_tag(self, obj):
63-
return obj.user.robot.avatar_tag()
64-
6554

6655
class LNPaymentInline(admin.StackedInline):
6756
model = LNPayment
@@ -510,7 +499,6 @@ class OnchainPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
510499
@admin.register(Robot)
511500
class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
512501
list_display = (
513-
"avatar_tag",
514502
"id",
515503
"user_link",
516504
"telegram_enabled",
@@ -523,9 +511,8 @@ class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
523511
)
524512
raw_id_fields = ("user",)
525513
list_editable = ["earned_rewards"]
526-
list_display_links = ("avatar_tag", "id")
514+
list_display_links = ["id"]
527515
change_links = ["user"]
528-
readonly_fields = ["avatar_tag"]
529516
search_fields = ["user__username", "id"]
530517
readonly_fields = ("hash_id", "public_key", "encrypted_private_key")
531518

api/views.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from datetime import datetime, timedelta
2-
from pathlib import Path
32

43
from decouple import config
54
from django.conf import settings
@@ -55,9 +54,6 @@
5554
EXP_MAKER_BOND_INVOICE = int(config("EXP_MAKER_BOND_INVOICE"))
5655
RETRY_TIME = int(config("RETRY_TIME"))
5756

58-
avatar_path = Path(settings.AVATAR_ROOT)
59-
avatar_path.mkdir(parents=True, exist_ok=True)
60-
6157

6258
class MakerView(CreateAPIView):
6359
serializer_class = MakeOrderSerializer

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Pillow==10.1.0
1616
python-decouple==3.8
1717
requests==2.31.0
1818
ring==0.10.1
19-
git+https://github.com/RoboSats/Robohash.git@master
2019
gunicorn==22.0.0
2120
psycopg2==2.9.9
2221
SQLAlchemy==2.0.16

robosats/middleware.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import hashlib
22
from datetime import timedelta
3-
from pathlib import Path
43

54
from channels.db import database_sync_to_async
65
from channels.middleware import BaseMiddleware
7-
from django.conf import settings
86
from django.contrib.auth.models import AnonymousUser, User, update_last_login
97
from django.utils import timezone
108
from django.utils.deprecation import MiddlewareMixin
119
from django.http import JsonResponse
1210
from rest_framework.authtoken.models import Token
13-
from robohash import Robohash
11+
from rest_framework.exceptions import AuthenticationFailed
1412

1513
from api.nick_generator.nick_generator import NickGenerator
1614
from api.utils import base91_to_hex, hex_to_base91, is_valid_token, validate_pgp_keys
@@ -19,9 +17,6 @@
1917
lang="English", use_adv=False, use_adj=True, use_noun=True, max_num=999
2018
)
2119

22-
avatar_path = Path(settings.AVATAR_ROOT)
23-
avatar_path.mkdir(parents=True, exist_ok=True)
24-
2520

2621
class DisableCSRFMiddleware(object):
2722
def __init__(self, get_response):
@@ -164,21 +159,6 @@ def __call__(self, request):
164159
if not user.robot.encrypted_private_key:
165160
user.robot.encrypted_private_key = encrypted_private_key
166161

167-
# Generate avatar. Does not replace if existing.
168-
image_path = avatar_path.joinpath(nickname + ".webp")
169-
if not image_path.exists():
170-
rh = Robohash(hash)
171-
rh.assemble(roboset="set1", bgset="any") # for backgrounds ON
172-
with open(image_path, "wb") as f:
173-
rh.img.save(f, format="WEBP", quality=80)
174-
175-
image_small_path = avatar_path.joinpath(nickname + ".small.webp")
176-
with open(image_small_path, "wb") as f:
177-
resized_img = rh.img.resize((80, 80))
178-
resized_img.save(f, format="WEBP", quality=80)
179-
180-
user.robot.avatar = "static/assets/avatars/" + nickname + ".webp"
181-
182162
update_last_login(None, user)
183163
user.save()
184164

robosats/settings.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
# Build paths inside the project like this: BASE_DIR / 'subdir'.
2424
BASE_DIR = Path(__file__).resolve().parent.parent
2525

26-
STATIC_URL = "/static/"
27-
2826
# Quick-start development settings - unsuitable for production
2927
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
3028

3129
# SECURITY WARNING: keep the secret key used in production secret!
3230
SECRET_KEY = config("SECRET_KEY")
3331

3432
DEBUG = False
33+
34+
# Static files (CSS, JavaScript, Images)
35+
# https://docs.djangoproject.com/en/4.0/howto/static-files/
3536
STATIC_URL = "static/"
36-
STATIC_ROOT = "/usr/src/static/"
3737

3838
# RoboSats version
3939
with open("version.json") as f:
@@ -42,9 +42,6 @@
4242
# SECURITY WARNING: don't run with debug turned on in production!
4343
if config("DEVELOPMENT", default=False):
4444
DEBUG = True
45-
STATIC_ROOT = "frontend/static/"
46-
47-
AVATAR_ROOT = STATIC_ROOT + "assets/avatars/"
4845

4946
ALLOWED_HOSTS = [
5047
config("HOST_NAME"),
@@ -228,10 +225,6 @@
228225

229226
USE_TZ = True
230227

231-
# Static files (CSS, JavaScript, Images)
232-
# https://docs.djangoproject.com/en/4.0/howto/static-files/
233-
234-
STATIC_URL = "static/"
235228
ASGI_APPLICATION = "robosats.routing.application"
236229

237230
CHANNEL_LAYERS = {

0 commit comments

Comments
 (0)