Refactor code structure; improve organization and readability across multiple files

This commit is contained in:
Yaro Kasear 2025-06-23 14:51:21 -05:00
parent 774c28e761
commit acacf39f8e
14 changed files with 380 additions and 217 deletions

View file

@ -1,5 +1,6 @@
from sqlalchemy.orm import joinedload, selectinload
from .models import User, Room, Inventory, WorkLog
from . import db
def eager_load_user_relationships(query):
return query.options(
@ -31,3 +32,15 @@ def eager_load_worklog_relationships(query):
def chunk_list(lst, chunk_size):
return [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]
def add_named_entities(items: list[str], model, attr: str, mapper: dict | None = None):
for name in items:
clean = name.strip()
if clean:
print(f"Creating new {attr}: {clean}")
new_obj = model(**{attr: clean})
db.session.add(new_obj)
if mapper is not None:
db.session.flush()
mapper[clean] = new_obj.id
print(f"New {attr} '{clean}' added with ID {new_obj.id}")