Skip to content

[fixes] Sentry-driven fixes and small perf wins#1073

Merged
frankrousseau merged 10 commits into
cgwire:mainfrom
frankrousseau:main
May 12, 2026
Merged

[fixes] Sentry-driven fixes and small perf wins#1073
frankrousseau merged 10 commits into
cgwire:mainfrom
frankrousseau:main

Conversation

@frankrousseau
Copy link
Copy Markdown
Contributor

Problems

  • N+1 queries on concepts and tasks lists (Sentry)
  • Duplicate-email Person create/update bypassed CRUD checks and crashed
  • prepare_shot crashed on orphan shots (deleted parent sequence/episode)
  • 4xx exceptions (WrongParameterException etc.) flooded Sentry
  • apply_criterions_to_db_query broke filter_by on joined Entity queries
  • Normalized movies falsely tagged BT.709, shifting colors on untagged sources (Fix Colour matching issue with H.264 files without color metadata #1071)
  • Concurrent preview-file deletion during prepare_and_store_movie raised FK violation
  • Deleting a playlist with active share links raised FK violation
  • Shared playlists had no download endpoint for non-mp4 source previews

Solutions

  • Eager-load entity_concept_links; skip Task.assignees selectinload when relations=False
  • Reject duplicate emails up-front in Persons CRUD
  • Tolerate missing sequence/episode in prepare_shot
  • Add expected 4xx exceptions to Sentry ignore_errors
  • Use explicit model-bound filters instead of filter_by in apply_criterions_to_db_query
  • Drop color_primaries/trc/colorspace ffmpeg output flags
  • Convert IntegrityError to PreviewFileNotFoundException in update_entity_preview
  • Delete share links before removing playlist
  • Add download route for shared playlist source previews

frankrousseau and others added 10 commits May 10, 2026 15:33
The lazy="joined" declared on Entity.entity_concept_links does not fire
when the query uses .add_columns(Project.name), causing an N+1 query
during serialization (one SELECT entity per concept). Force a batched
selectin load so all linked entities are fetched in a single extra query
regardless of the main query shape.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
_get_entity_task_query always applied selectinload(Task.assignees) even
when callers pass relations=False, in which case Task.serialize drops
join attributes and the loaded Person rows are discarded. On large
episodes selectinload chunks at 500 IDs, producing many redundant
SELECT task ... JOIN person spans flagged as N+1 by Sentry. Apply the
option only when relations=True and propagate the flag through every
caller of the helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The Person CRUD endpoints relied on the only_one_email_by_person
partial unique index to catch duplicate emails, surfacing the
violation as an opaque IntegrityError raised mid-flight by an
autoflush in BaseMixin.update_no_commit (the Department.get(id) loop
forces a flush after email is already set on the instance). The
client received the raw "duplicate key value violates unique
constraint" message and Sentry logged the exception at error level,
turning routine user mistakes into ongoing noise.

Validate email uniqueness explicitly in PersonsResource creation
and PersonResource update against the same predicate as the partial
index (is_bot is not true), excluding self on update. Bot accounts
still bypass the check, matching the index definition.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
filter_by resolves attributes against the last joined entity, which
broke get_assets when episode_id forced an EntityLink join and another
criterion (e.g. project_id) was supplied. Use field_key == value so the
filter clauses carry the model's table reference and stay valid through
joins.
ffmpeg's color_primaries/trc/colorspace output flags only tag the
metadata, they don't convert pixels. On untagged H.264 sources (typical
After Effects export), claiming BT.709 makes players reinterpret the
pixel data and shifts perceived colors. Drop the tags so ffmpeg leaves
the output's color metadata unset and players fall back to their
resolution-based heuristics.

Fix cgwire#1071
The preview file can be deleted between the existence check and the
entity.update() commit, surfacing as a ForeignKeyViolation on fk_main_preview
in async pipelines like prepare_and_store_movie. Catch the IntegrityError
and convert it to PreviewFileNotFoundException so existing callers reuse
their graceful path for that case.
PlaylistShareLink.playlist_id has no ON DELETE clause, so deleting a
playlist that still owns share links surfaced as a ForeignKeyViolation
at commit time (Sentry: playlist_share_link_playlist_id_fkey). Mirror
the existing remove_playlist pattern (notifications, build jobs) and
delete share links before the playlist itself.
… playlists

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@frankrousseau frankrousseau merged commit 247cfca into cgwire:main May 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Colour matching issue with H.264 files without color metadata

1 participant