update
This commit is contained in:
@@ -285,6 +285,9 @@ db = Database()
|
||||
_LOG_QUEUE: Queue[tuple[str, str, str]] = Queue()
|
||||
_LOG_THREAD_STARTED = False
|
||||
_LOG_THREAD_LOCK = threading.Lock()
|
||||
_LOG_WRITE_COUNT = 0
|
||||
_LOG_PRUNE_INTERVAL = 500 # prune every N successful writes
|
||||
_LOG_MAX_AGE_DAYS = 7 # keep logs for this many days
|
||||
|
||||
|
||||
def _ensure_log_db_schema() -> None:
|
||||
@@ -323,6 +326,7 @@ def _log_worker_loop() -> None:
|
||||
"""Background log writer using a temporary per-write connection with
|
||||
small retry/backoff and a file fallback when writes fail repeatedly.
|
||||
"""
|
||||
global _LOG_WRITE_COUNT
|
||||
while True:
|
||||
level, module, message = _LOG_QUEUE.get()
|
||||
try:
|
||||
@@ -340,6 +344,14 @@ def _log_worker_loop() -> None:
|
||||
cur = conn.cursor()
|
||||
cur.execute("INSERT INTO logs (level, module, message) VALUES (?, ?, ?)", (level, module, message))
|
||||
conn.commit()
|
||||
_LOG_WRITE_COUNT += 1
|
||||
if _LOG_WRITE_COUNT % _LOG_PRUNE_INTERVAL == 0:
|
||||
try:
|
||||
cutoff = (datetime.datetime.utcnow() - datetime.timedelta(days=_LOG_MAX_AGE_DAYS)).strftime("%Y-%m-%d %H:%M:%S")
|
||||
cur.execute("DELETE FROM logs WHERE timestamp < ?", (cutoff,))
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
cur.close()
|
||||
conn.close()
|
||||
written = True
|
||||
|
||||
@@ -2092,7 +2092,7 @@ def expand_tag_lists(tags_set: Set[str]) -> Set[str]:
|
||||
return tags_set
|
||||
|
||||
try:
|
||||
with open(adjective_path, "r") as f:
|
||||
with open(adjective_path, "r", encoding="utf-8") as f:
|
||||
adjective_lists = json.load(f)
|
||||
except Exception as e:
|
||||
debug(f"Error loading adjective.json: {e}")
|
||||
|
||||
Reference in New Issue
Block a user