mirror of
https://github.com/krateng/maloja.git
synced 2025-04-23 20:10:27 +03:00
MOOOORE PERFORMANCE!!!
This commit is contained in:
parent
d0f265d3ca
commit
0ed2cd2e35
@ -400,10 +400,12 @@ def get_charts_artists(dbconn=None,resolve_ids=True,**keys):
|
||||
separate = keys.get('separate',False)
|
||||
result = sqldb.count_scrobbles_by_artist(since=since,to=to,resolve_ids=resolve_ids,associated=(not separate),dbconn=dbconn)
|
||||
|
||||
map = sqldb.get_associated_artist_map([entry['artist'] for entry in result if 'artist' in entry])
|
||||
for entry in result:
|
||||
if "artist" in entry:
|
||||
entry['associated_artists'] = map[entry['artist']]
|
||||
if resolve_ids:
|
||||
# only add associated info if we resolve
|
||||
map = sqldb.get_associated_artist_map(artist_ids=[entry['artist_id'] for entry in result if 'artist_id' in entry])
|
||||
for entry in result:
|
||||
if "artist_id" in entry:
|
||||
entry['associated_artists'] = map[entry['artist_id']]
|
||||
return result
|
||||
|
||||
@waitfordb
|
||||
|
@ -1449,8 +1449,12 @@ def get_associated_artists(*artists,resolve_ids=True,dbconn=None):
|
||||
|
||||
@cached_wrapper
|
||||
@connection_provider
|
||||
def get_associated_artist_map(artists,resolve_ids=True,dbconn=None):
|
||||
artist_ids = [get_artist_id(a,dbconn=dbconn) for a in artists]
|
||||
def get_associated_artist_map(artists=[],artist_ids=None,resolve_ids=True,dbconn=None):
|
||||
|
||||
ids_supplied = (artist_ids is not None)
|
||||
|
||||
if not ids_supplied:
|
||||
artist_ids = [get_artist_id(a,dbconn=dbconn) for a in artists]
|
||||
|
||||
|
||||
jointable = sql.join(
|
||||
@ -1476,7 +1480,9 @@ def get_associated_artist_map(artists,resolve_ids=True,dbconn=None):
|
||||
else:
|
||||
artists_to_associated[row.target_artist].append(row.id)
|
||||
|
||||
artists_to_associated = {artists[artist_ids.index(k)]:v for k,v in artists_to_associated.items()}
|
||||
if not ids_supplied:
|
||||
# if we supplied the artists, we want to convert back for the result
|
||||
artists_to_associated = {artists[artist_ids.index(k)]:v for k,v in artists_to_associated.items()}
|
||||
|
||||
return artists_to_associated
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user