fix: close library upload flow and harden image storage
Community checks / verify (push) Skipped
Verify Frame Flow / verify (push) Successful in 8m9s

This commit is contained in:
渡口浪人
2026-10-24 00:38:00 +08:00
parent 0859871363
commit 1494904b12
39 changed files with 1471 additions and 240 deletions
+22 -6
View File
@@ -17,6 +17,7 @@ def encode(value):
class Database:
def __init__(self, path):
self.lock = threading.RLock()
self._transaction_depth = 0
self.conn = sqlite3.connect(path, check_same_thread=False)
self.conn.row_factory = sqlite3.Row
self.conn.executescript("""
@@ -68,17 +69,32 @@ class Database:
@contextmanager
def transaction(self):
with self.lock:
self.conn.execute("BEGIN IMMEDIATE")
nested = self._transaction_depth > 0
savepoint = "tx_" + str(self._transaction_depth)
self.conn.execute("SAVEPOINT " + savepoint if nested else "BEGIN IMMEDIATE")
self._transaction_depth += 1
try:
yield self.conn
self.conn.commit()
except Exception:
self.conn.rollback()
if nested:
self.conn.execute("RELEASE SAVEPOINT " + savepoint)
else:
self.conn.commit()
except BaseException:
if nested:
self.conn.execute("ROLLBACK TO SAVEPOINT " + savepoint)
self.conn.execute("RELEASE SAVEPOINT " + savepoint)
else:
self.conn.rollback()
raise
finally:
self._transaction_depth -= 1
def execute(self, query, args=()):
with self.lock, self.conn:
return self.conn.execute(query, args)
with self.lock:
if self._transaction_depth:
return self.conn.execute(query, args)
with self.conn:
return self.conn.execute(query, args)
def one(self, query, args=()):
with self.lock: