Performance tweaks

This commit is contained in:
krateng 2023-10-27 18:06:12 +02:00
parent 43e67680cd
commit 6caa6f9016
4 changed files with 49 additions and 62 deletions

View File

@ -63,6 +63,8 @@ def waitfordb(func):
def newfunc(*args,**kwargs):
if not dbstatus['healthy']: raise exceptions.DatabaseNotBuilt()
return func(*args,**kwargs)
newfunc.__name__ = func.__name__
return newfunc
@ -421,8 +423,12 @@ def get_charts_tracks(dbconn=None,resolve_ids=True,**keys):
@waitfordb
def get_charts_albums(dbconn=None,resolve_ids=True,**keys):
(since,to) = keys.get('timerange').timestamps()
appearing = keys.get('appearing',False)
if 'artist' in keys:
result = sqldb.count_scrobbles_by_album_of_artist(since=since,to=to,artist=keys['artist'],associated=keys.get('associated',False),resolve_ids=resolve_ids,dbconn=dbconn)
if appearing:
result = sqldb.count_scrobbles_of_artist_by_album(since=since,to=to,artist=keys['artist'],associated=keys.get('associated',False),resolve_ids=resolve_ids,dbconn=dbconn)
else:
result = sqldb.count_scrobbles_by_album_of_artist(since=since,to=to,artist=keys['artist'],associated=keys.get('associated',False),resolve_ids=resolve_ids,dbconn=dbconn)
else:
result = sqldb.count_scrobbles_by_album(since=since,to=to,resolve_ids=resolve_ids,dbconn=dbconn)
return result
@ -736,14 +742,17 @@ def album_info(dbconn=None,reduced=False,**keys):
if not album_id: raise exceptions.AlbumDoesNotExist(album['albumtitle'])
album = sqldb.get_album(album_id,dbconn=dbconn)
alltimecharts = get_charts_albums(timerange=alltime(),dbconn=dbconn)
#scrobbles = get_scrobbles_num(track=track,timerange=alltime())
c = [e for e in alltimecharts if e["album"] == album][0]
scrobbles = c["scrobbles"]
position = c["rank"]
extrainfo = {}
if reduced:
scrobbles = get_scrobbles_num(album=album,timerange=alltime())
else:
alltimecharts = get_charts_albums(timerange=alltime(),dbconn=dbconn)
c = [e for e in alltimecharts if e["album"] == album][0]
scrobbles = c["scrobbles"]
position = c["rank"]
extrainfo['position'] = position
cert = None
threshold_gold, threshold_platinum, threshold_diamond = malojaconfig["SCROBBLES_GOLD_ALBUM","SCROBBLES_PLATINUM_ALBUM","SCROBBLES_DIAMOND_ALBUM"]
@ -752,7 +761,7 @@ def album_info(dbconn=None,reduced=False,**keys):
elif scrobbles >= threshold_gold: cert = "gold"
if reduced:
extrainfo = {}
pass
else:
twk = thisweek()
tyr = thisyear()
@ -782,7 +791,6 @@ def album_info(dbconn=None,reduced=False,**keys):
return {
"album":album,
"scrobbles":scrobbles,
"position":position,
"certification":cert,
"id":album_id,
**extrainfo

View File

@ -51,6 +51,8 @@ if malojaconfig['USE_GLOBAL_CACHE']:
cache[key] = result
return result
outer_func.__name__ = f"cache_wrap_{inner_func.__name__}"
return outer_func

View File

@ -157,6 +157,7 @@ def connection_provider(func):
return func(*args,**kwargs)
wrapper.__innerfunc__ = func
wrapper.__name__ = f"connection_provider_{func.__name__}"
return wrapper
@connection_provider
@ -1184,7 +1185,7 @@ def count_scrobbles_of_artist_by_album(since,to,artist,associated=False,resolve_
if resolve_ids:
albums = get_albums_map([row.album_id for row in result],dbconn=dbconn)
result = [{'scrobbles':row.count,'album':albums[row.album_id],'album_id':row.album_id} for row in result]
result = [{'scrobbles':row.count,'album':albums[row.album_id],'album_id':row.album_id} for row in result if row.album_id]
else:
result = [{'scrobbles':row.count,'album_id':row.album_id} for row in result]
result = rank(result,key='scrobbles')

View File

@ -1,80 +1,56 @@
{% import 'snippets/links.jinja' as links %}
{% set info = dbc.get_albums_artist_appears_on(filterkeys,limitkeys) %}
{% set ownalbums = info.own_albums %}
{% set otheralbums = info.appears_on %}
<div id="showcase_container">
{% for album in ownalbums %}
{% set info = dbc.album_info({'album':album,'reduced':True}) %}
{% for entry in dbc.get_charts_albums(filterkeys,limitkeys,{'appearing':False}) %}
{%- set cert = None -%}
{%- if entry.scrobbles >= settings.scrobbles_gold_album -%}{% set cert = 'gold' %}{%- endif -%}
{%- if entry.scrobbles >= settings.scrobbles_platinum_album -%}{% set cert = 'platinum' %}{%- endif -%}
{%- if entry.scrobbles >= settings.scrobbles_diamond_album -%}{% set cert = 'diamond' %}{%- endif -%}
<table class="album">
<tr><td>&nbsp</td></tr>
<tr><td>
<a href="{{ links.url(album) }}">
<div class="shiny alwaysshiny certified_{{ info.certification }} lazy" data-bg="{{ images.get_album_image(album) }}"'></div>
<a href="{{ links.url(entry.album) }}">
<div class="shiny alwaysshiny certified_{{ cert }} lazy" data-bg="{{ images.get_album_image(entry.album) }}"'></div>
</a>
</td></tr>
<tr><td>
<span class="album_artists">{{ links.links(album.artists) }}</span><br/>
<span class="album_title">{{ links.link(album) }}</span>
<span class="album_artists">{{ links.links(entry.album.artists) }}</span><br/>
<span class="album_title">{{ links.link(entry.album) }}</span>
</td></tr>
</table>
{% endfor %}
{% for album in otheralbums %}
{% set info = dbc.album_info({'album':album,'reduced':True}) %}
{% for entry in dbc.get_charts_albums(filterkeys,limitkeys,{'appearing':True}) %}
{% if artist not in (entry.album.artists or []) %}
{%- set cert = None -%}
{%- if entry.scrobbles >= settings.scrobbles_gold_album -%}{% set cert = 'gold' %}{%- endif -%}
{%- if entry.scrobbles >= settings.scrobbles_platinum_album -%}{% set cert = 'platinum' %}{%- endif -%}
{%- if entry.scrobbles >= settings.scrobbles_diamond_album -%}{% set cert = 'diamond' %}{%- endif -%}
<table class="album">
<tr><td>Appears on</td></tr>
<tr><td>
<a href="{{ links.url(album) }}">
<div class="shiny alwaysshiny certified_{{ info.certification }} lazy" data-bg="{{ images.get_album_image(album) }}"'></div>
<a href="{{ links.url(entry.album) }}">
<div class="shiny alwaysshiny certified_{{ cert }} lazy" data-bg="{{ images.get_album_image(entry.album) }}"'></div>
</a>
</td></tr>
<tr><td>
<span class="album_artists">{{ links.links(album.artists) }}</span><br/>
<span class="album_title">{{ links.link(album) }}</span>
<span class="album_artists">{{ links.links(entry.album.artists) }}</span><br/>
<span class="album_title">{{ links.link(entry.album) }}</span>
</td></tr>
</table>
{% endif %}
{% endfor %}
<!--
<table class="album_showcase">
<tr>
{% for album in ownalbums %}<td></td>{% endfor %}
{% if ownalbums and otheralbums%}<td class="album_separator_column"></td>{% endif %}
{% for album in otheralbums %}<td>Appears on</td>{% endfor %}
</tr>
<tr>
{% for album in ownalbums %}
<td>
<a href="{{ links.url(album) }}">
<div class="lazy" data-bg="{{ images.get_album_image(album) }}"'></div>
</a>
</td>
{% endfor %}
{% if ownalbums and otheralbums%}<td class="album_separator_column"></td>{% endif %}
{% for album in otheralbums %}
<td class="album_appearon">
<a href="{{ links.url(album) }}">
<div class="lazy" data-bg="{{ images.get_album_image(album) }}"'></div>
</a>
</td>
{% endfor %}
</tr>
<tr>
{% for album in ownalbums %}
<td>{{ album.albumtitle }}</td>
{% endfor %}
{% if ownalbums and otheralbums%}<td class="album_separator_column"></td>{% endif %}
{% for album in otheralbums %}
<td>{{ album.albumtitle }}</td>
{% endfor %}
</tr>
</table>
-->
</div>