Skip to content

Eliminate N+1 queries in character-order display and editing - #749

Open
DeusExTaco wants to merge 2 commits into
GrandComicsDatabase:betafrom
DeusExTaco:fix/issue-731-character-order-n-plus-one
Open

Eliminate N+1 queries in character-order display and editing#749
DeusExTaco wants to merge 2 commits into
GrandComicsDatabase:betafrom
DeusExTaco:fix/issue-731-character-order-n-plus-one

Conversation

@DeusExTaco

Copy link
Copy Markdown
Contributor

Summary

I eliminated the per-character database queries in character-order display and editing flows.

  • Bulk-load character identity and alias relationships once per display/edit operation.
  • Bulk-load character-order through rows instead of calling get() for each appearance.
  • Batch removals, updates, and inserts in the character-order editing view.
  • Preserve ordering and alias/civilian display behavior.

Testing

  • apps/oi/tests/db/test_character_order_revision.py: 7 passed
  • Story/revision compatibility suite: 71 passed
  • Added query-bound regression coverage for display and edit preparation.

Closes #731

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes character and story-character ordering queries by introducing a bulk-loading cache (_build_character_identity_cache) for alias and civilian identities, and by batching database operations (using bulk_create and bulk_update) during character reordering. These changes significantly reduce the number of database queries. However, a critical bug was identified in apps/gcd/models/story.py where querying story_character__story_character_id instead of story_character_id for character revisions causes ID mismatches and breaks the editing flow.

Comment thread apps/gcd/models/story.py
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.

Eliminate N+1 queries in character-order display and editing

1 participant