modified: app.py
This commit is contained in:
10
app.py
10
app.py
@@ -139,21 +139,21 @@ def fetch_and_cache_profile_picture(user_id, avatar_url):
|
||||
|
||||
|
||||
def get_profile_picture(user_id, avatar_url):
|
||||
"""Versucht, das Profilbild eines Benutzers aus Redis, lokalem Speicher und zuletzt durch Download zu holen."""
|
||||
# 1. Versuch: Redis
|
||||
"""Gibt den Pfad zum Profilbild eines Benutzers zurück, zuerst aus Redis, dann aus dem lokalen Speicher und zuletzt durch Download."""
|
||||
# 1. Prüfen, ob das Bild in Redis gecached ist
|
||||
cached_image = r.get(str(user_id))
|
||||
if cached_image:
|
||||
print(f"Redis cache hit for user {user_id}: {cached_image}")
|
||||
return cached_image.decode('utf-8')
|
||||
|
||||
# 2. Versuch: Lokaler Speicher
|
||||
# 2. Prüfen, ob das Bild lokal gespeichert ist
|
||||
local_image_path = os.path.join(PROFILE_IMAGE_DIR, f"{user_id}.png")
|
||||
if os.path.exists(local_image_path):
|
||||
print(f"Local cache hit for user {user_id}")
|
||||
r.set(str(user_id), local_image_path) # Cache das Bild in Redis
|
||||
r.set(str(user_id), local_image_path) # Speichern in Redis
|
||||
return local_image_path
|
||||
|
||||
# 3. Download und Cache des Bilds
|
||||
# 3. Wenn das Bild weder in Redis noch lokal ist, herunterladen und speichern
|
||||
print(f"Downloading profile picture for user {user_id}")
|
||||
return fetch_and_cache_profile_picture(user_id, avatar_url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user