agregado cache a get_artist_of_disc
This commit is contained in:
@@ -199,9 +199,9 @@ def get_discs_of_artist(mbid, limit, page):
|
||||
key_count = f'artist_{mbid}:release_group_count'
|
||||
if key_count in redis:
|
||||
key = f'artist_{mbid}:release_groups'
|
||||
if int(redis.get(key_count)) == redis.llen(key):
|
||||
mb_discs_ids = redis.lrange(key, offset, limit)
|
||||
mb_discs = [get_disc(mbid) for mbid in mb_discs_ids]
|
||||
mb_disc_ids = redis.lrange(key, offset, limit)
|
||||
if redis.exists(*[f'release_group_{mbid}' for mbid in mb_disc_ids]) == len(mb_disc_ids):
|
||||
mb_discs = [get_disc(mbid) for mbid in mb_disc_ids]
|
||||
total = redis.llen(key)
|
||||
|
||||
if len(mb_discs) == 0:
|
||||
@@ -221,17 +221,28 @@ def get_discs_of_artist(mbid, limit, page):
|
||||
}
|
||||
|
||||
|
||||
def get_artist_of_disc(mbid, limit, page):
|
||||
def get_artist_of_disc(mbid):
|
||||
"""Obtiene el artista de un disco"""
|
||||
mb_artists = mb.browse_artists(params={'release-group': mbid},
|
||||
limit=limit, offset=limit * (page - 1))
|
||||
|
||||
if 'error' in mb_artists:
|
||||
return mb_artists
|
||||
mb_artist = None
|
||||
|
||||
with get_redis_connection() as redis:
|
||||
key_id = f'release_group_{mbid}:artist'
|
||||
if key_id in redis:
|
||||
mb_artist = get_artist(redis.get(key_id))
|
||||
|
||||
if mb_artist is None:
|
||||
mb_artist_browse = mb.browse_artists(params={'release-group': mbid}, limit=0, offset=0)
|
||||
|
||||
if 'error' in mb_artist_browse:
|
||||
return mb_artist_browse
|
||||
|
||||
mb_artist = mb_artist_browse.get('artists')[0]
|
||||
|
||||
jobs.load_artist_on_cache.delay(mb_artist)
|
||||
|
||||
return {
|
||||
'paginate': paginate(mb_artists.get('artist_count', 0), limit, page),
|
||||
'artists': [map_artist(artist) for artist in mb_artists['artists']]
|
||||
'artist': map_artist(mb_artist)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user