fixes #1 and fixes #2. also identifies issue with DELETE_ORPHANS sql command

This commit is contained in:
worldveil 2013-11-29 22:08:25 -05:00
parent 90a93bc47b
commit 51680735db
3 changed files with 20 additions and 13 deletions

View file

@ -1,5 +1,5 @@
from dejavu.database import SQLDatabase from dejavu.database import SQLDatabase
from dejavu.converter import Converter from dejavu.convert import Converter
from dejavu.fingerprint import Fingerprinter from dejavu.fingerprint import Fingerprinter
from scipy.io import wavfile from scipy.io import wavfile
from multiprocessing import Process from multiprocessing import Process
@ -62,8 +62,9 @@ class Dejavu():
p.join() p.join()
# delete orphans # delete orphans
print "Done fingerprinting. Deleting orphaned fingerprints..." # print "Done fingerprinting. Deleting orphaned fingerprints..."
self.fingerprinter.db.delete_orphans() # TODO: need a more performant query in database.py for the
#self.fingerprinter.db.delete_orphans()
def fingerprint_worker(self, files, sql_connection, output): def fingerprint_worker(self, files, sql_connection, output):

View file

@ -102,7 +102,11 @@ class SQLDatabase():
# delete # delete
DELETE_UNFINGERPRINTED = "DELETE FROM %s WHERE %s = 0;" % (SONGS_TABLENAME, FIELD_FINGERPRINTED) DELETE_UNFINGERPRINTED = "DELETE FROM %s WHERE %s = 0;" % (SONGS_TABLENAME, FIELD_FINGERPRINTED)
DELETE_ORPHANS = "" DELETE_ORPHANS = """
delete from fingerprints
where not exists (
select * from songs where fingerprints.song_id = songs.song_id
)"""
def __init__(self, hostname, username, password, database): def __init__(self, hostname, username, password, database):
# connect # connect
@ -154,13 +158,14 @@ class SQLDatabase():
def delete_orphans(self): def delete_orphans(self):
try: try:
self.cursor = self.connection.cursor() self.cursor = self.connection.cursor()
self.cursor.execute(SQLDatabase.DELETE_ORPHANS) ### TODO: SQLDatabase.DELETE_ORPHANS is not performant enough, need better query
self.connection.commit() ### to delete fingerprints for which no song is tied to.
#self.cursor.execute(SQLDatabase.DELETE_ORPHANS)
#self.connection.commit()
except mysql.Error, e: except mysql.Error, e:
print "Error in delete_orphans(), %d: %s" % (e.args[0], e.args[1]) print "Error in delete_orphans(), %d: %s" % (e.args[0], e.args[1])
self.connection.rollback() self.connection.rollback()
def delete_unfingerprinted_songs(self): def delete_unfingerprinted_songs(self):
try: try:
self.cursor = self.connection.cursor() self.cursor = self.connection.cursor()

View file

@ -197,13 +197,14 @@ class Fingerprinter():
largest_count = diff_counter[diff][sid] largest_count = diff_counter[diff][sid]
song_id = sid song_id = sid
if verbose: print "Diff is %d with %d offset-aligned matches" % (largest, largest_count) if verbose:
print "Diff is %d with %d offset-aligned matches" % (largest, largest_count)
#from collections import OrderedDict # extract idenfication
#print OrderedDict(diff_counter) song = self.db.get_song_by_id(song_id)
songname = song.get(SQLDatabase.FIELD_SONGNAME, None)
# extract idenfication if not songname:
songname = self.db.get_song_by_id(song_id)[SQLDatabase.FIELD_SONGNAME] return None
songname = songname.replace("_", " ") songname = songname.replace("_", " ")
elapsed = time.time() - starttime elapsed = time.time() - starttime