1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Ensured idempotence of scrobbles with timestamp

This commit is contained in:
Krateng 2019-08-15 15:51:01 +02:00
parent 89881af8fe
commit 3ae30a5226

View File

@ -107,9 +107,18 @@ def get_track_dict(o):
def createScrobble(artists,title,time,volatile=False): def createScrobble(artists,title,time,volatile=False):
dblock.acquire() dblock.acquire()
i = getTrackID(artists,title)
# idempotence
if time in SCROBBLESDICT:
if i == SCROBBLESDICT[time].track:
dblock.release()
return get_track_dict(TRACKS[i])
# timestamp as unique identifier
while (time in SCROBBLESDICT): while (time in SCROBBLESDICT):
time += 1 time += 1
i = getTrackID(artists,title)
obj = Scrobble(i,time,volatile) # if volatile generated, we simply pretend we have already saved it to disk obj = Scrobble(i,time,volatile) # if volatile generated, we simply pretend we have already saved it to disk
#SCROBBLES.append(obj) #SCROBBLES.append(obj)
# immediately insert scrobble correctly so we can guarantee sorted list # immediately insert scrobble correctly so we can guarantee sorted list