Agregando jobs para rellenar el cache de datos
This commit is contained in:
@@ -4,9 +4,14 @@ Su objetivo es modificar los datos que entrega musicbrainz para que sean
|
||||
correspondientes con lo que debe entregar la api, se encarga de casos como
|
||||
traducción.
|
||||
"""
|
||||
import json
|
||||
from math import ceil
|
||||
|
||||
from django.core.cache import cache
|
||||
from country_list import countries_for_language
|
||||
|
||||
import fetcher.musicbrainz as mb
|
||||
from fetcher import jobs
|
||||
|
||||
|
||||
###
|
||||
@@ -150,11 +155,17 @@ def map_coverart(mb_cover):
|
||||
|
||||
def get_artist(mbid):
|
||||
"""Obtiene un artista desde musicbrainz incluyendo sus tags"""
|
||||
mb_artist = mb.get_artist_by_mbid(mbid, includes=['tags'])
|
||||
|
||||
mb_artist = cache.get(f'artist_{mbid}')
|
||||
if mb_artist is None:
|
||||
mb_artist = mb.get_artist_by_mbid(mbid, includes=['tags'])
|
||||
else:
|
||||
mb_artist = json.loads(mb_artist)
|
||||
if 'error' in mb_artist:
|
||||
return mb_artist
|
||||
|
||||
jobs.load_artist_on_cache.delay(mbid)
|
||||
|
||||
return map_artist(mb_artist)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user