mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented caching of image links on disk
This commit is contained in:
parent
80686fd4e1
commit
6540af0e55
@ -618,6 +618,9 @@ def build_db():
|
|||||||
global db_rulestate
|
global db_rulestate
|
||||||
db_rulestate = consistentRulestate("scrobbles",cla.checksums)
|
db_rulestate = consistentRulestate("scrobbles",cla.checksums)
|
||||||
|
|
||||||
|
# load cached images
|
||||||
|
loadCache()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -654,6 +657,9 @@ def sync():
|
|||||||
lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
||||||
log("Database saved to disk.")
|
log("Database saved to disk.")
|
||||||
|
|
||||||
|
# save cached images
|
||||||
|
saveCache()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BIN
mediacache
Normal file
BIN
mediacache
Normal file
Binary file not shown.
@ -68,7 +68,7 @@ def shutdown():
|
|||||||
graceful_exit()
|
graceful_exit()
|
||||||
|
|
||||||
def graceful_exit(sig=None,frame=None):
|
def graceful_exit(sig=None,frame=None):
|
||||||
urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/sync")
|
urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync")
|
||||||
log("Server shutting down...")
|
log("Server shutting down...")
|
||||||
os._exit(42)
|
os._exit(42)
|
||||||
|
|
||||||
|
20
utilities.py
20
utilities.py
@ -2,6 +2,7 @@ import re
|
|||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
|
||||||
### TSV files
|
### TSV files
|
||||||
@ -211,6 +212,25 @@ def apirequest(artists=None,artist=None,title=None):
|
|||||||
cachedTracks = {}
|
cachedTracks = {}
|
||||||
cachedArtists = {}
|
cachedArtists = {}
|
||||||
|
|
||||||
|
def saveCache():
|
||||||
|
fl = open("mediacache","wb")
|
||||||
|
stream = pickle.dumps((cachedTracks,cachedArtists))
|
||||||
|
fl.write(stream)
|
||||||
|
fl.close()
|
||||||
|
|
||||||
|
def loadCache():
|
||||||
|
try:
|
||||||
|
fl = open("mediacache","rb")
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
ob = pickle.loads(fl.read())
|
||||||
|
global cachedTracks, cachedArtists
|
||||||
|
(cachedTracks, cachedArtists) = ob
|
||||||
|
finally:
|
||||||
|
fl.close()
|
||||||
|
|
||||||
def getTrackInfo(artists,title):
|
def getTrackInfo(artists,title):
|
||||||
|
|
||||||
obj = (frozenset(artists),title)
|
obj = (frozenset(artists),title)
|
||||||
|
Loading…
Reference in New Issue
Block a user