I eliminated the per-character database queries in character-order display and editing flows.
get() for each appearance.apps/oi/tests/db/test_character_order_revision.py: 7 passedCloses #731
https://github.com/GrandComicsDatabase/gcd-django/pull/749
(4 files)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@gemini-code-assist[bot] commented on this pull request.
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.
> + if field == 'character_revisions':
+ through_rows = through_rows.values(
+ 'story_character__story_character_id', 'order_code')
+ order_codes = {
+ row['story_character__story_character_id']: row['order_code']
+ for row in through_rows
+ }
In the character_revisions branch, through_rows is queried from CharacterThroughOrderRevision (which connects CharacterOrderRevision to StoryCharacterRevision).
Using 'story_character__story_character_id' selects the ID of the production StoryCharacter model. However, all_appearing_characters contains StoryCharacterRevision instances, so member.id is compared against in_character_order_ids using StoryCharacterRevision IDs. Because StoryCharacter IDs and StoryCharacterRevision IDs do not match, the character order matching logic fails completely in the editing flow. Additionally, for newly added characters, story_character_id is None until committed, which would result in None keys.
To fix this, we should query 'story_character_id' directly, which retrieves the StoryCharacterRevision IDs and correctly aligns with member.id.
- if field == 'character_revisions':
- through_rows = through_rows.values(
- 'story_character__story_character_id', 'order_code')
- order_codes = {
- row['story_character__story_character_id']: row['order_code']
- for row in through_rows
- }
+ if field == 'character_revisions':
+ through_rows = through_rows.values(
+ 'story_character_id', 'order_code')
+ order_codes = {
+ row['story_character_id']: row['order_code']
+ for row in through_rows
+ }
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@DeusExTaco pushed 1 commit.
—
View it on GitHub or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()