1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Gave image request a bit of time to resolve

This commit is contained in:
krateng 2023-04-01 17:02:41 +02:00
parent 72826f87fe
commit cbb1e0b2c2

View File

@ -16,12 +16,14 @@ from threading import Lock
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
import re import re
import datetime import datetime
import time
import sqlalchemy as sql import sqlalchemy as sql
MAX_RESOLVE_THREADS = 5 MAX_RESOLVE_THREADS = 5
MAX_SECONDS_TO_RESOLVE_REQUEST = 5
# remove old db file (columns missing) # remove old db file (columns missing)
@ -263,23 +265,31 @@ def resolve_image(artist_id=None,track_id=None,album_id=None):
# the actual http request for the full image # the actual http request for the full image
def image_request(artist_id=None,track_id=None,album_id=None): def image_request(artist_id=None,track_id=None,album_id=None):
# check cache
result = get_image_from_cache(artist_id=artist_id,track_id=track_id,album_id=album_id) # because we use lazyload, we can allow our http requests to take a little while at least
if result is not None: # not the full backend request, but a few seconds to give us time to fetch some images
# we got an entry, even if it's that there is no image (value None) # because 503 retry-after doesn't seem to be honored
if result['value'] is None: attempt = 0
# use placeholder while attempt < MAX_SECONDS_TO_RESOLVE_REQUEST:
placeholder_url = "https://generative-placeholders.glitch.me/image?width=300&height=300&style=" attempt += 1
if artist_id: # check cache
result['value'] = placeholder_url + f"tiles&colors={artist_id % 100}" result = get_image_from_cache(artist_id=artist_id,track_id=track_id,album_id=album_id)
if track_id: if result is not None:
result['value'] = placeholder_url + f"triangles&colors={track_id % 100}" # we got an entry, even if it's that there is no image (value None)
if album_id: if result['value'] is None:
result['value'] = placeholder_url + f"joy-division&colors={album_id % 100}" # use placeholder
return result placeholder_url = "https://generative-placeholders.glitch.me/image?width=300&height=300&style="
else: if artist_id:
# no entry, which means we're still working on it result['value'] = placeholder_url + f"tiles&colors={artist_id % 100}"
return {'type':'noimage','value':'wait'} if track_id:
result['value'] = placeholder_url + f"triangles&colors={track_id % 100}"
if album_id:
result['value'] = placeholder_url + f"joy-division&colors={album_id % 100}"
return result
time.sleep(1)
# no entry, which means we're still working on it
return {'type':'noimage','value':'wait'}