Faster implementation

This commit is contained in:
ville rantanen
2013-04-10 14:02:30 +03:00
parent b43254bdc8
commit e697b78e94

View File

@@ -93,10 +93,12 @@ def add_recurse(options):
if not options.symlinks:
files=clean_syms(files)
files.sort()
db_files=get_folder_contents(db,os.path.abspath(path)+'/')
for file in files:
if IMGMATCH.match(file):
filename=os.path.abspath(os.path.join(path,file))
if not is_listed(db,filename):
#if not is_listed(db,filename):
if file not in db_files:
if options.add:
add_single(conn,filename,change=False,minsize=options.minsize)
else:
@@ -108,7 +110,7 @@ def add_recurse(options):
#file content changed
add_single(conn,filename,change=True,minsize=options.minsize)
# if file mentioned, and hash same, no need to change entry
conn.commit()
return
def add_single(conn,filename,change=False,hash=None,minsize=0):
@@ -132,7 +134,6 @@ def add_single(conn,filename,change=False,hash=None,minsize=0):
db.execute("INSERT INTO list(file,date,portrait,hash,width,height)\
VALUES(?,?,?,?,?,?)",(filename,ftime,portrait,hash,dims[0],dims[1]))
print "adding: %(f)s (%(x)sx%(y)s)" % {'f':filename, 'x':dims[0], 'y':dims[1]}
conn.commit()
return
def random_lists(sqlfile):
@@ -162,6 +163,16 @@ def is_listed(db,filename):
count=db.fetchall()
return count[0][0]>0
def get_folder_contents(db,path):
''' return the contents of the folder '''
files=[]
db.execute("SELECT file FROM list where file LIKE ?",(path+'%',))
for row in db:
base=row[0].replace(path,'',1)
if base.find('/')==-1:
files.append(base)
return files
def ftime_match(db,filename,ftime):
db.execute("SELECT date FROM list where file == ?",(filename,))
count=db.fetchall()