1
0
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:
Krateng 2019-02-16 16:42:45 +01:00
parent 80686fd4e1
commit 6540af0e55
4 changed files with 27 additions and 1 deletions

View File

@ -618,6 +618,9 @@ def build_db():
global db_rulestate
db_rulestate = consistentRulestate("scrobbles",cla.checksums)
# load cached images
loadCache()
@ -653,6 +656,9 @@ def sync():
global lastsync
lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
log("Database saved to disk.")
# save cached images
saveCache()

BIN
mediacache Normal file

Binary file not shown.

View File

@ -68,7 +68,7 @@ def shutdown():
graceful_exit()
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...")
os._exit(42)

View File

@ -2,6 +2,7 @@ import re
import os
import hashlib
from threading import Thread
import pickle
### TSV files
@ -211,6 +212,25 @@ def apirequest(artists=None,artist=None,title=None):
cachedTracks = {}
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):
obj = (frozenset(artists),title)