Merge master

This commit is contained in:
Oliver Falk
2025-10-27 13:39:17 +01:00
3 changed files with 12 additions and 3 deletions

View File

@@ -86,6 +86,10 @@ MAX_PIXELS = 7000
AVATAR_MAX_SIZE = 512 AVATAR_MAX_SIZE = 512
JPEG_QUALITY = 85 JPEG_QUALITY = 85
# Robohash Performance Optimization
# Enable optimized robohash implementation for 6-22x performance improvement
ROBOHASH_OPTIMIZATION_ENABLED = True
# Robohash Configuration # Robohash Configuration
# Maximum number of robot parts to cache in memory (each ~50-200KB) # Maximum number of robot parts to cache in memory (each ~50-200KB)
ROBOHASH_CACHE_SIZE = 150 # ~10-30MB total cache size ROBOHASH_CACHE_SIZE = 150 # ~10-30MB total cache size

View File

@@ -16,8 +16,9 @@ class OptimizedRobohash(Robohash):
""" """
Performance-optimized version of Robohash that: Performance-optimized version of Robohash that:
1. Caches directory structure to avoid repeated filesystem scans 1. Caches directory structure to avoid repeated filesystem scans
2. Reduces natsort calls from 163 to ~10 per generation 2. Eliminates double resizing (1024x1024 -> target size)
3. Provides 2-6x performance improvement while maintaining 100% compatibility 3. Reduces natsort calls from 163 to ~10 per generation
4. Provides 6-22x performance improvement while maintaining 100% compatibility
""" """
# Class-level cache shared across all instances # Class-level cache shared across all instances
@@ -226,7 +227,9 @@ class OptimizedRobohash(Robohash):
# Add background if specified # Add background if specified
if background_path: if background_path:
try: try:
bg = Image.open(background_path).resize((1024, 1024)) bg = Image.open(background_path).resize(
(sizex, sizey), Image.LANCZOS
)
bg.paste(roboimg, (0, 0), roboimg) bg.paste(roboimg, (0, 0), roboimg)
roboimg = bg roboimg = bg
except Exception: except Exception:

View File

@@ -27,6 +27,7 @@ from monsterid.id import build_monster as BuildMonster
import Identicon import Identicon
from pydenticon5 import Pydenticon5 from pydenticon5 import Pydenticon5
import pagan import pagan
from .robohash_optimized import create_optimized_robohash
from .robohash_cached import create_robohash from .robohash_cached import create_robohash
from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY, DEFAULT_AVATAR_SIZE from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY, DEFAULT_AVATAR_SIZE
@@ -273,6 +274,7 @@ class AvatarImageView(TemplateView):
return self._return_cached_png(monsterdata, data, uri) return self._return_cached_png(monsterdata, data, uri)
if str(default) == "robohash": if str(default) == "robohash":
roboset = request.GET.get("robohash") or "any" roboset = request.GET.get("robohash") or "any"
data = create_optimized_robohash(kwargs["digest"], size, roboset)
data = create_robohash(kwargs["digest"], size, roboset) data = create_robohash(kwargs["digest"], size, roboset)
return self._return_cached_response(data, uri) return self._return_cached_response(data, uri)
if str(default) == "retro": if str(default) == "retro":