-
Notifications
You must be signed in to change notification settings - Fork 0
24 add indexes and search #52
Conversation
|
A couple of things to think about after Claude and I ran scalability tests:
|
|
1: Deep pages get slower the deeper you go (name and difficulty). The documentation says «a page costs the same on page 1 and page 10 000». Measured: name ascending 2 ms at the start, 12 ms after 20 000, 48 ms after 150 000. Code is constant (2–3 ms). The cause is in EXPLAIN: the id condition ends up as a filter and not as an index bound (Rows Removed by Filter: 115 141). Rows that share the same sort value (all without a name have nameSort = '', and difficulty has only 10 values) are read from the start of the group every time. In the real catalog 69 % have no name.
|
|
No limit on the number of search words. 100 words took 0.7 seconds, and 300 words took 14 seconds in a single query. A single request can load the database. Needs a cap (for example 10 words and 100 characters) that gives BAD_USER_INPUT, and it must be in the documentation. |
|
Two extra database calls per search page. Each page with an apparatus and group filter makes 2 lookups (3 queries instead of 1). The catalog is static, so the lookups can be cached in memory or done once. |
|
I want to bring this up again in connection with search. I seem to remember that this was a deliberate decision, but I am just double-checking that we did this on purpose. If so, we should update the UI to have an indication that there are several variants, which we do not have now. In the Code of Points some elements have the same code and the same value, but several ways of performing them. Code UB-1.206 has two:
In the database they are two separate rows, but in the search list only one row per code is shown, and it is always -a. The other variant is only shown when you open the detail page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see commetns
|
Thanks for the review! Here is what's done with each point, and why. Changed
Kept as it isNumbers match by prefix Not in this PRProof on a large catalog Showing variants in the search list Docs
|
|
changes seems addressed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Keeps both AI_USAGE sections. The other changes from dev (Tailwind, shadcn/ui, the colours) merged without conflicts. Lint, typecheck, build and all 45 tests pass, with the database tests run against the seeded catalog.
Summary
Adds the catalog search function that the
searchCatalogresolver will call. There is no GraphQL server on dev yet, so nothing calls it yet.What it does
CatalogEntryandCatalogWordwith Prisma only. A new lint rule fails the build if someone uses raw SQLtotalCount)Decisions
normalizeWords), so "hop-grip", "sec." and "1/1" find what is stored. The search only adds removing a trailing "s".BAD_USER_INPUT, not an empty list, so a typo in the client is noticed.The reasons for each are in "Search without raw SQL" in
docs/API.md.How to test
npm run db:seedso the catalog is in your databasenpm testDATABASE_URLinbackend/.env, the search tests are skipped, and the run still passesCloses #24
🤖 Generated with Claude Code