Added ability to discourage CPU-heavy statistics

This commit is contained in:
Krateng 2020-10-05 03:15:06 +02:00
parent cbd93d2b33
commit 90d6e67e97
No known key found for this signature in database
GPG Key ID: 46735607861C6FCE
4 changed files with 17 additions and 3 deletions

View File

@ -67,6 +67,10 @@ DEFAULT_STEP_PULSE = month
# display top tiles on artist and track chart pages
CHARTS_DISPLAY_TILES = false
# this does not actually block any requests, it's just an interface feature t
# prevent visitors from mindlessly clicking on those options and hogging your cpu
DISCOURAGE_CPU_HEAVY_STATS = false
[Fluff]
# how many scrobbles a track needs to aquire this status

View File

@ -55,7 +55,7 @@ def update_jinja_environment():
{"identifier":"alltime","localisation":"All Time","range":malojatime.alltime()}
],
"xdelimiters": [
{"identifier":"daily","replacekeys":{"step":"day","stepn":1},"localisation":"Daily"},
{"identifier":"daily","replacekeys":{"step":"day","stepn":1},"localisation":"Daily","heavy":True},
{"identifier":"weekly","replacekeys":{"step":"week","stepn":1},"localisation":"Weekly"},
{"identifier":"fortnightly","replacekeys":{"step":"week","stepn":2},"localisation":"Fortnightly"},
{"identifier":"monthly","replacekeys":{"step":"month","stepn":1},"localisation":"Monthly"},
@ -66,8 +66,8 @@ def update_jinja_environment():
{"identifier":"standard","replacekeys":{"trail":1},"localisation":"Standard"},
{"identifier":"trailing","replacekeys":{"trail":2},"localisation":"Trailing"},
{"identifier":"longtrailing","replacekeys":{"trail":3},"localisation":"Long Trailing"},
{"identifier":"inert","replacekeys":{"trail":10},"localisation":"Inert"},
{"identifier":"cumulative","replacekeys":{"trail":math.inf},"localisation":"Cumulative"}
{"identifier":"inert","replacekeys":{"trail":10},"localisation":"Inert","heavy":True},
{"identifier":"cumulative","replacekeys":{"trail":math.inf},"localisation":"Cumulative","heavy":True}
]
}

View File

@ -4,6 +4,7 @@
{% set allkeys = [filterkeys,limitkeys,delimitkeys,amountkeys] | combine_dicts %}
{% if limitkeys != {} %}
<div>
@ -30,6 +31,8 @@
{% for r in xcurrent %}
{% if r.range == limitkeys.timerange %}
<span class='stat_selector' style='opacity:0.5;'>{{ r.localisation }}</span>
{% elif r.heavy and settings('DISCOURAGE_CPU_HEAVY_STATS') %}
<span class='stat_selector blocked' title="CPU heavy statistics are discouraged at the moment.">{{ r.localisation }}</span>
{% else %}
<a href='{{ mlj_uri.create_uri("",allkeys,{"timerange":r.range}) }}'><span class='stat_selector'>{{ r.localisation }}</span></a>
{% endif %}
@ -46,6 +49,8 @@
{# {% if all(r.keys[k] == allkeys[k] for k in r.keys) %} #}
{% if r.replacekeys | map('compare_key_in_dicts',r.replacekeys,allkeys) | alltrue %}
<span class='stat_selector' style='opacity:0.5;'>{{ r.localisation }}</span>
{% elif r.heavy and settings('DISCOURAGE_CPU_HEAVY_STATS') %}
<span class='stat_selector blocked' title="CPU heavy statistics are discouraged at the moment.">{{ r.localisation }}</span>
{% else %}
<a href='{{ mlj_uri.create_uri("",allkeys,r.replacekeys) }}'><span class='stat_selector'>{{ r.localisation }}</span></a>
{% endif %}

View File

@ -258,6 +258,11 @@ table.top_info + .stat_module_toptracks table {
font-size:80%;
}
.blocked {
opacity:0.2;
cursor:not-allowed;
}
input#apikey {
font-family:'Ubuntu';