From 5c5e63dbea949bd43758b8ada040f67a98ce2cb5 Mon Sep 17 00:00:00 2001 From: Zeecka Date: Wed, 31 Dec 2025 16:25:54 +0100 Subject: [PATCH] SKIP IHDR and Clear at restart --- .env | 2 ++ aperisolve/models.py | 18 ++++++++++++++---- compose.dev.yml | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 549b813..366a17d 100644 --- a/.env +++ b/.env @@ -2,6 +2,8 @@ MAX_CONTENT_LENGTH=1048576 MAX_PENDING_TIME=600 MAX_STORE_TIME=259200 +CLEAR_AT_RESTART=1 +SKIP_IHDR_FILL=1 # Flask configuration FLASK_DEBUG=0 diff --git a/aperisolve/models.py b/aperisolve/models.py index b064689..6b300f8 100644 --- a/aperisolve/models.py +++ b/aperisolve/models.py @@ -5,6 +5,9 @@ import itertools from datetime import datetime, timezone +from os import getenv +from pathlib import Path +from shutil import rmtree from flask import Flask from flask_sqlalchemy import SQLAlchemy @@ -128,9 +131,16 @@ def init_db(app: Flask) -> None: """ with app.app_context(): if not db.engine.dialect.has_table(db.engine.connect(), "image"): - print("Creating database...") + print(f"CLEAR_AT_RESTART={getenv('CLEAR_AT_RESTART', '0')}") + if getenv("CLEAR_AT_RESTART", "0") == "1": + print("Clearing database and file system at restart...") + db.drop_all() # Clear existing tables if configured + rmtree(Path("./results"), ignore_errors=True) # Clear results folder db.create_all() print("Database structure created successfully.") - print("Filling IHDR lookup table...") - create_crc_db() - print("IHDR table filled successfully.") + if getenv("SKIP_IHDR_FILL", "0") == "1": + print("Skipping IHDR lookup table fill as per configuration.") + else: + print("Filling IHDR lookup table...") + create_crc_db() + print("IHDR table filled successfully.") diff --git a/compose.dev.yml b/compose.dev.yml index c10943f..523ee2f 100644 --- a/compose.dev.yml +++ b/compose.dev.yml @@ -22,6 +22,7 @@ services: environment: - FLASK_DEBUG=true - FLASK_ENV=development + - SKIP_IHDR_FILL=1 worker: #image: ghcr.io/zeecka/aperisolve:latest