mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Some performance improvements
This commit is contained in:
46
database.py
46
database.py
@@ -179,14 +179,12 @@ def get_scrobbles_external():
|
|||||||
return {"list":result}
|
return {"list":result}
|
||||||
|
|
||||||
def get_scrobbles(**keys):
|
def get_scrobbles(**keys):
|
||||||
r = db_query(**{k:keys[k] for k in keys if k in ["artist","artists","title","since","to","within","associated","track"]})
|
r = db_query(**{k:keys[k] for k in keys if k in ["artist","artists","title","since","to","within","associated","track","max_"]})
|
||||||
r.reverse()
|
#if keys.get("max_") is not None:
|
||||||
|
# return r[:int(keys.get("max_"))]
|
||||||
if keys.get("max_") is not None:
|
#else:
|
||||||
return r[:int(keys.get("max_"))]
|
# return r
|
||||||
else:
|
return r
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -826,7 +824,7 @@ def check_cache_age():
|
|||||||
|
|
||||||
|
|
||||||
# Queries the database
|
# Queries the database
|
||||||
def db_query_full(artist=None,artists=None,title=None,track=None,since=None,to=None,within=None,associated=False):
|
def db_query_full(artist=None,artists=None,title=None,track=None,since=None,to=None,within=None,associated=False,max_=None):
|
||||||
|
|
||||||
(since, to) = time_stamps(since,to,within)
|
(since, to) = time_stamps(since,to,within)
|
||||||
|
|
||||||
@@ -859,15 +857,20 @@ def db_query_full(artist=None,artists=None,title=None,track=None,since=None,to=N
|
|||||||
elif artist is None and track is None and artists is not None and len(artists) != 0:
|
elif artist is None and track is None and artists is not None and len(artists) != 0:
|
||||||
artist = artists.pop()
|
artist = artists.pop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# db query always reverse by default
|
||||||
if associated:
|
|
||||||
#return [getScrobbleObject(s) for s in SCROBBLES if (s[0] == track or track==None) and (artist==None or artist in coa.getCreditedList(TRACKS[s[0]][0])) and (since < s[1] < to)]
|
result = []
|
||||||
return [getScrobbleObject(s) for s in scrobbles_in_range(since,to) if (track is None or s[0] == track) and (artist is None or artist in coa.getCreditedList(TRACKS[s[0]][0]))]
|
|
||||||
else:
|
i = 0
|
||||||
#return [getScrobbleObject(s) for s in SCROBBLES if (s[0] == track or track==None) and (artist==None or artist in TRACKS[s[0]][0]) and (since < s[1] < to)]
|
for s in scrobbles_in_range(since,to,reverse=True):
|
||||||
return [getScrobbleObject(s) for s in scrobbles_in_range(since,to) if (track is None or s[0] == track) and (artist is None or artist in TRACKS[s[0]][0])]
|
if i == max_: break
|
||||||
|
if (track is None or s[0] == track) and (artist is None or artist in TRACKS[s[0]][0] or associated and artist in coa.getCreditedList(TRACKS[s[0]][0])):
|
||||||
|
result.append(getScrobbleObject(s))
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
# pointless to check for artist when track is checked because every track has a fixed set of artists, but it's more elegant this way
|
# pointless to check for artist when track is checked because every track has a fixed set of artists, but it's more elegant this way
|
||||||
|
|
||||||
|
|
||||||
@@ -967,25 +970,20 @@ def insert(list_,item,key=lambda x:x):
|
|||||||
list_.append(item)
|
list_.append(item)
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
def scrobbles_in_range(start,end,reverse=False):
|
def scrobbles_in_range(start,end,reverse=False):
|
||||||
if reverse:
|
if reverse:
|
||||||
for stamp in reversed(STAMPS):
|
for stamp in reversed(STAMPS):
|
||||||
#print("Checking " + str(stamp))
|
#print("Checking " + str(stamp))
|
||||||
if stamp < start: return
|
if stamp < start: return
|
||||||
if stamp > end: continue
|
if stamp > end: continue
|
||||||
yield SCROBBLESDICT[stamp]
|
yield SCROBBLESDICT[stamp]
|
||||||
else:
|
else:
|
||||||
for stamp in STAMPS:
|
for stamp in STAMPS:
|
||||||
#print("Checking " + str(stamp))
|
#print("Checking " + str(stamp))
|
||||||
if stamp < start: continue
|
if stamp < start: continue
|
||||||
if stamp > end: return
|
if stamp > end: return
|
||||||
yield SCROBBLESDICT[stamp]
|
yield SCROBBLESDICT[stamp]
|
||||||
|
|
||||||
#for stamp in range(start,end+1):
|
|
||||||
# if stamp%1000 == 0: print("testing " + str(stamp))
|
|
||||||
# if stamp in SCROBBLESDICT:
|
|
||||||
# yield SCROBBLESDICT[stamp]
|
|
||||||
|
|
||||||
|
|
||||||
# for performance testing
|
# for performance testing
|
||||||
|
|||||||
@@ -16,12 +16,16 @@ import urllib
|
|||||||
|
|
||||||
|
|
||||||
# artist=None,track=None,since=None,to=None,within=None,associated=False,max_=None,pictures=False
|
# artist=None,track=None,since=None,to=None,within=None,associated=False,max_=None,pictures=False
|
||||||
def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,**kwargs):
|
def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,earlystop=False,**kwargs):
|
||||||
|
|
||||||
kwargs_filter = pickKeys(kwargs,"artist","track","associated")
|
kwargs_filter = pickKeys(kwargs,"artist","track","associated")
|
||||||
kwargs_time = pickKeys(kwargs,"since","to","within")
|
kwargs_time = pickKeys(kwargs,"since","to","within")
|
||||||
|
|
||||||
scrobbles = database.get_scrobbles(**kwargs_time,**kwargs_filter) #we're getting all scrobbles for the number and only filtering them on site
|
|
||||||
|
# if earlystop, we don't care about the actual amount and only request as many from the db
|
||||||
|
# without, we request everything and filter on site
|
||||||
|
maxkey = {"max_":max_} if earlystop else {}
|
||||||
|
scrobbles = database.get_scrobbles(**kwargs_time,**kwargs_filter,**maxkey)
|
||||||
if pictures:
|
if pictures:
|
||||||
scrobbleswithpictures = scrobbles if max_ is None else scrobbles[:max_]
|
scrobbleswithpictures = scrobbles if max_ is None else scrobbles[:max_]
|
||||||
#scrobbleimages = [e.get("image") for e in getTracksInfo(scrobbleswithpictures)] #will still work with scrobble objects as they are a technically a subset of track objects
|
#scrobbleimages = [e.get("image") for e in getTracksInfo(scrobbleswithpictures)] #will still work with scrobble objects as they are a technically a subset of track objects
|
||||||
|
|||||||
@@ -185,6 +185,9 @@ def clock(*args):
|
|||||||
print(args[0] + ": " + str(now - measurement))
|
print(args[0] + ": " + str(now - measurement))
|
||||||
measurement = now
|
measurement = now
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Media info
|
### Media info
|
||||||
|
|
||||||
def apirequest(artists=None,artist=None,title=None):
|
def apirequest(artists=None,artist=None,title=None):
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def instructions(keys):
|
|||||||
|
|
||||||
|
|
||||||
# scrobbles
|
# scrobbles
|
||||||
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True)
|
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True)
|
||||||
|
|
||||||
clock("Scrobbles")
|
clock("Scrobbles")
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ def instructions(keys):
|
|||||||
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
|
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
|
||||||
|
|
||||||
data = database.trackInfo(track["artists"],track["title"])
|
data = database.trackInfo(track["artists"],track["title"])
|
||||||
|
|
||||||
scrobblesnum = str(data["scrobbles"])
|
scrobblesnum = str(data["scrobbles"])
|
||||||
pos = "#" + str(data["position"])
|
pos = "#" + str(data["position"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
html_scrobbles, _, _ = module_scrobblelist(track=track,max_=100)
|
html_scrobbles, _, _ = module_scrobblelist(track=track,max_=100,earlystop=True) # we have the number already from the trackinfo
|
||||||
|
|
||||||
html_pulse = module_pulse(track=track,step="year",stepn=1,trail=1)
|
html_pulse = module_pulse(track=track,step="year",stepn=1,trail=1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user