migrate entry module to contextual transactions
parent
b0ffbaf4ca
commit
7bb07e0343
|
|
@ -82,9 +82,9 @@ def check_image_browser_active_tabs():
|
|||
last_default_tab = wib_db.get_last_default_tab()
|
||||
if last_default_tab[0] == "Others":
|
||||
# New tabs don't exist yet in image_browser_active_tabs, add them
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
with wib_db.transaction() as cursor:
|
||||
wib_db.update_db_data(cursor, "last_default_tab", "Maintenance")
|
||||
wib_db.transaction_end(conn, cursor)
|
||||
|
||||
if hasattr(opts, "image_browser_active_tabs"):
|
||||
active_and_new_tabs = f"{opts.image_browser_active_tabs}, All, Maintenance"
|
||||
shared.opts.__setattr__("image_browser_active_tabs", active_and_new_tabs)
|
||||
|
|
@ -457,7 +457,7 @@ def cache_exif(fileinfos):
|
|||
cache_exif_start = time.time()
|
||||
new_exif = 0
|
||||
new_aes = 0
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
with wib_db.transaction() as cursor:
|
||||
for fi_info in fileinfos:
|
||||
if any(fi_info[0].endswith(ext) for ext in image_ext_list):
|
||||
found_exif = False
|
||||
|
|
@ -537,7 +537,6 @@ def cache_exif(fileinfos):
|
|||
aes_cache[fi_info[0]] = aes_value
|
||||
wib_db.update_exif_data_by_key(conn, fi_info[0], "aesthetic_score", aes_value)
|
||||
new_aes = new_aes + 1
|
||||
wib_db.transaction_end(conn, cursor)
|
||||
|
||||
if yappi_do:
|
||||
yappi.stop()
|
||||
|
|
@ -573,9 +572,8 @@ def exif_rebuild(maint_wait):
|
|||
def exif_delete_0(maint_wait):
|
||||
global exif_cache, aes_cache
|
||||
if opts.image_browser_scan_exif:
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
with wib_db.transaction() as cursor:
|
||||
wib_db.delete_exif_0(cursor)
|
||||
wib_db.transaction_end(conn, cursor)
|
||||
exif_cache = wib_db.load_exif_data(exif_cache)
|
||||
aes_cache = wib_db.load_aes_data(aes_cache)
|
||||
maint_last_msg = "Delete finished"
|
||||
|
|
@ -594,7 +592,7 @@ def exif_update_dirs(maint_update_dirs_path_recorder, maint_update_dirs_exif_dat
|
|||
maint_update_dirs_from = os.path.realpath(maint_update_dirs_from)
|
||||
maint_update_dirs_to = os.path.realpath(maint_update_dirs_to)
|
||||
rows = 0
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
with wib_db.transaction() as cursor:
|
||||
if maint_update_dirs_path_recorder:
|
||||
wib_db.update_path_recorder_mult(cursor, maint_update_dirs_from, maint_update_dirs_to)
|
||||
rows = rows + cursor.rowcount
|
||||
|
|
@ -604,7 +602,6 @@ def exif_update_dirs(maint_update_dirs_path_recorder, maint_update_dirs_exif_dat
|
|||
if maint_update_dirs_ranking:
|
||||
wib_db.update_ranking_mult(cursor, maint_update_dirs_from, maint_update_dirs_to)
|
||||
rows = rows + cursor.rowcount
|
||||
wib_db.transaction_end(conn, cursor)
|
||||
if rows == 0:
|
||||
maint_last_msg = "No rows updated"
|
||||
else:
|
||||
|
|
@ -614,9 +611,8 @@ def exif_update_dirs(maint_update_dirs_path_recorder, maint_update_dirs_exif_dat
|
|||
|
||||
def recreate_hash(maint_wait):
|
||||
version = str(db_version)
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
with wib_db.transaction() as cursor:
|
||||
wib_db.migrate_filehash(cursor, version)
|
||||
wib_db.transaction_end(conn, cursor)
|
||||
maint_last_msg = "Hashes recreated"
|
||||
|
||||
return maint_wait, maint_last_msg
|
||||
|
|
@ -632,8 +628,7 @@ def reapply_ranking(path_recorder, maint_wait):
|
|||
if os.path.exists(key):
|
||||
dirs[key] = key
|
||||
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
|
||||
with wib_db.transaction() as cursor:
|
||||
# Traverse all known dirs, check if missing rankings are due to moved files
|
||||
for key in dirs.keys():
|
||||
fileinfos = traverse_all_files(key, [], "", 0)
|
||||
|
|
@ -658,7 +653,6 @@ def reapply_ranking(path_recorder, maint_wait):
|
|||
# Replace ranking of the found filename
|
||||
wib_db.replace_ranking(cursor, file, alternate_file, hash)
|
||||
|
||||
wib_db.transaction_end(conn, cursor)
|
||||
maint_last_msg = "Rankings reapplied"
|
||||
|
||||
return maint_wait, maint_last_msg
|
||||
|
|
@ -743,7 +737,7 @@ def get_all_images(dir_name, sort_by, sort_order, keyword, tab_base_tag_box, img
|
|||
filenames = [finfo[0] for finfo in fileinfos]
|
||||
|
||||
if opts.image_browser_scan_exif:
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
with wib_db.transaction() as cursor:
|
||||
if len(exif_keyword) != 0:
|
||||
if use_regex:
|
||||
regex_error = False
|
||||
|
|
@ -809,8 +803,6 @@ def get_all_images(dir_name, sort_by, sort_order, keyword, tab_base_tag_box, img
|
|||
fileinfos = wib_db.filter_ranking(cursor, fileinfos, ranking_filter, ranking_filter_min_num, ranking_filter_max_num)
|
||||
filenames = [finfo[0] for finfo in fileinfos]
|
||||
|
||||
wib_db.transaction_end(conn, cursor)
|
||||
|
||||
if sort_by == "date":
|
||||
if sort_order == up_symbol:
|
||||
fileinfos = sorted(fileinfos, key=lambda x: x[1].st_mtime)
|
||||
|
|
@ -905,11 +897,11 @@ def get_image_thumbnail(image_list):
|
|||
|
||||
def set_tooltip_info(image_list):
|
||||
image_browser_img_info = {}
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
with wib_db.transaction() as cursor:
|
||||
for filename in image_list:
|
||||
x, y = wib_db.select_x_y(cursor, filename)
|
||||
image_browser_img_info[filename] = {"x": x, "y": y}
|
||||
wib_db.transaction_end(conn, cursor)
|
||||
|
||||
image_browser_img_info_json = json.dumps(image_browser_img_info)
|
||||
return image_browser_img_info_json
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue