better db call order

This commit is contained in:
Justus Kuhlmann 2025-11-27 11:07:55 +01:00
commit 64579c477c
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6

View file

@ -6,7 +6,7 @@ from .input import sfcf,openQCD
import json
from typing import Union, Optional
from pyerrors import Obs, Corr, load_object, dump_object
from hashlib import sha256
from hashlib import sha256, sha1
from .tools import cached, record2name_key, make_version_hash
from .cache_io import is_in_cache, cache_path, cache_dir, get_version_hash
@ -85,18 +85,12 @@ def write_measurement(path, ensemble, measurement, uuid, code, parameter_file: O
meas_path = file_in_archive + "::" + par_hash
meas_paths.append(meas_path)
known_meas[par_hash] = measurement[corr][subkey]
if c.execute("SELECT * FROM backlogs WHERE path = ?", (meas_path,)).fetchone() is not None:
c.execute("UPDATE backlogs SET updated_at = datetime('now') WHERE path = ?", (meas_path, ))
else:
c.execute("INSERT INTO backlogs (name, ensemble, code, path, project, parameters, parameter_file, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))",
data_hash = sha1(pj.create_json_string(measurement[corr][subkey]).encode('UTF-8')).hexdigest()
if c.execute("SELECT * FROM backlogs WHERE path = ?", (meas_path,)).fetchone() is None:
c.execute("INSERT INTO backlogs (name, ensemble, code, path, project, parameters, parameter_file, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'))",
(corr, ensemble, code, meas_path, uuid, pars[subkey], parameter_file))
conn.commit()
c.execute("UPDATE backlogs SET current_version = ?, updated_at = datetime('now') WHERE path = ?", (data_hash, meas_path))
pj.dump_dict_to_json(known_meas, file)
for meas_path in meas_paths:
version_hash = make_version_hash(path, meas_path)
print(version_hash)
c.execute("UPDATE backlogs SET current_version = ? WHERE project = ? AND code = ? and name = ?", (version_hash, uuid, code, corr))
conn.commit()
files.append(db)
conn.close()