mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-14 10:52:21 +02:00
Preserve preview harness, editor, email and task improvements
Snapshot current maintainer-preview application changes and regression fixtures for integration into lab. Excludes local runtime data, evaluation outputs and source backups. Focused Python regression selection: 140 passed; full suite not certified.
This commit is contained in:
@@ -81,24 +81,44 @@ def session_image_refs(db, session_id: str) -> tuple[set[str], set[str]]:
|
||||
return image_ids, filenames
|
||||
|
||||
|
||||
def session_gallery_images(db, session_id: str):
|
||||
"""Gallery images belonging to this chat, including legacy tool records."""
|
||||
_, GalleryImage, _ = _database_models()
|
||||
image_ids, filenames = session_image_refs(db, session_id)
|
||||
query = db.query(GalleryImage).filter(GalleryImage.session_id == session_id)
|
||||
if image_ids or filenames:
|
||||
from sqlalchemy import or_
|
||||
|
||||
clauses = [GalleryImage.session_id == session_id]
|
||||
if image_ids:
|
||||
clauses.append(GalleryImage.id.in_(list(image_ids)))
|
||||
if filenames:
|
||||
clauses.append(GalleryImage.filename.in_(list(filenames)))
|
||||
query = db.query(GalleryImage).filter(or_(*clauses))
|
||||
from core.database import Session
|
||||
owner_row = db.query(Session.owner).filter(Session.id == session_id).first()
|
||||
if owner_row is not None:
|
||||
query = query.filter(GalleryImage.owner == owner_row[0])
|
||||
# A reference to an image belonging to another chat is not ownership.
|
||||
from sqlalchemy import or_
|
||||
return query.filter(or_(GalleryImage.session_id == session_id, GalleryImage.session_id.is_(None)))
|
||||
|
||||
|
||||
def preserve_session_images(session_id: str, db) -> None:
|
||||
"""Detach gallery images before removing the chat; keep files and albums."""
|
||||
_, GalleryImage, _ = _database_models()
|
||||
db.query(GalleryImage).filter(GalleryImage.session_id == session_id).update(
|
||||
{GalleryImage.session_id: None}, synchronize_session=False
|
||||
)
|
||||
|
||||
|
||||
def cleanup_session_images(session_id: str, db=None) -> int:
|
||||
"""Soft-delete Gallery rows and unlink generated files owned by a chat."""
|
||||
_, GalleryImage, SessionLocal = _database_models()
|
||||
owns_db = db is None
|
||||
db = db or SessionLocal()
|
||||
try:
|
||||
image_ids, filenames = session_image_refs(db, session_id)
|
||||
query = db.query(GalleryImage).filter(GalleryImage.session_id == session_id)
|
||||
if image_ids or filenames:
|
||||
from sqlalchemy import or_
|
||||
|
||||
clauses = [GalleryImage.session_id == session_id]
|
||||
if image_ids:
|
||||
clauses.append(GalleryImage.id.in_(list(image_ids)))
|
||||
if filenames:
|
||||
clauses.append(GalleryImage.filename.in_(list(filenames)))
|
||||
query = db.query(GalleryImage).filter(or_(*clauses))
|
||||
|
||||
query = session_gallery_images(db, session_id)
|
||||
images = query.all()
|
||||
removed = 0
|
||||
for img in images:
|
||||
|
||||
Reference in New Issue
Block a user