Skip to content

Fix the box page N+1 queries; type-to-filter for the box assign list and the storage and consumables forms - #215

Merged
olsonjp merged 2 commits into
mainfrom
box-page-n-plus-one-and-assign-picker
Nov 11, 2026
Merged

olsonjp merged 2 commits into
mainfrom
box-page-n-plus-one-and-assign-picker

Conversation

@olsonjp

@olsonjp olsonjp commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Closes #207
Closes #209

#207: N+1 queries on the box page (Sentry PYTHON-DJANGO-37 and -38)

The box detail page (/storage/detail/box/<id>/) built its slot grid with one locations.get(row=..., column=...) per slot (about 100 queries for a 10 x 10 box), and the template then looked up each occupied slot's aliquot type and disposition separately.

  • The grid is now built from one query for the box's positions, indexed by (row, column), with the sample, type and disposition loaded together. The list of positions is also sorted by row and column; before, its order was undefined.
  • Tests compare query counts (after a warm-up request): the count is the same for a box with 2 or 60 aliquots, for a 2 x 2 or a 10 x 10 box, and does not change when other boxes are full.
  • The fix commit message references the Sentry issues through this PR; after deploy, check that PYTHON-DJANGO-37 and -38 stop recurring and resolve them.

#209: type-to-filter for the rest of the forms

Continues #212, which did the aliquot and sample forms.

  • Box page, "Assign aliquot": no longer loads every aliquot in the database (about 10,700 rows on every box view). It uses the same search picker as Parent aliquot (/samples/aliquot-options/) and starts empty each time the modal opens.
  • The modal itself is themed. Its header, footer, title, close button and fields were hardcoded light greys, so in dark mode the title was nearly invisible and the text box was white. The body also no longer scrolls: the global modal rule gave it a 60vh scroll box that clipped the open list, and a general rule now lets any modal that holds the control show its list in full.
  • The control's text box takes the select's own classes, so it picks up each page's input styling automatically (it had lost the modal's form-control).
  • Storage forms (Device, Shelf, Rack, Box) and Consumables forms (Consumable, Consumable type, Location) get type-to-filter on their dropdowns. Lists shorter than 8 options stay plain selects.
  • Parents in the labels: shelves and racks are named with their parents (Freezer A › Shelf 1, Freezer A › Shelf 1 › Rack 1), since names repeat across devices and typing to find one would be ambiguous.
  • A small N+1 on the consumable form: consumable locations are named "Room / Name" but loaded the room once per option; fixed. Both form changes are covered by query-count tests.

"Create New Boxe"

Reported while testing: the list pages formed the singular by chopping the last letter (model_name|slice:\":-1\"), which gives "Boxe" and "Shelve". A new singular template filter (in sample_tags) replaces it in all ten places across the sample, storage and consumables lists: Boxes becomes Box, Shelves becomes Shelf, Categories becomes Category, Aliquot Types becomes Aliquot Type, and case is kept. The storage and consumables lists also said "1 boxes found"; they now say "1 box found".

Not changed

No migrations or model changes. The assign view itself is unchanged: it still takes aliquot_id, and the picker offers any non-deleted aliquot, as the old dropdown did.

Verification

  • storage/tests/test_box_page.py (28 tests): the query counts above, the grid and counts, the picker markup and reset, the modal theme and no-scroll rules, assigning, the storage and consumables form labels and marks, and the singular filter and its pages. Full suite on the merged branch: 855 tests, OK. makemigrations --check is clean.
  • The control's behaviour (opening, filtering, choosing, the keyboard) still has no automated tests, as in Type-to-filter dropdowns for the aliquot and sample forms (part of #209) #212. Not checked by me: how any of this looks in a browser.

Please check

  • Box page: click an empty slot, type in the picker, choose an aliquot, assign it; try dark mode (title, footer and text box should match the body, and the list should not be clipped or scroll).
  • Shelf, Rack and Box forms, and the Consumable form: dropdowns filter as you type; the Parent labels read well.
  • Consumable form: changing the type still shows its type-specific fields.
  • "Create New Box", "Create New Shelf", and "1 box found".

🤖 Generated with Claude Code

olsonjp and others added 2 commits November 11, 2026 11:02
…storage and consumables forms; singular filter

Closes #207.
Closes #209.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@olsonjp
olsonjp merged commit 54168d0 into main Nov 11, 2026
1 check passed
@olsonjp
olsonjp deleted the box-page-n-plus-one-and-assign-picker branch November 11, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant