chore: simplify review follow-ups (memoize sort, cache npm, trim comments)#90
Merged
chore: simplify review follow-ups (memoize sort, cache npm, trim comments)#90
Conversation
Three targeted wins from /simplify review — net +19/-23 lines.
1. Pre-sort FLASHCARD_COURSE_MAP once at module load.
`Object.entries(map).sort((a,b) => b[0].length - a[0].length)` was
running inside each URL→course resolve in content.js and
sidebar-chat.js. Map has ~30 entries and resolve fires on every SPA
nav, so it's not a real hot path — but a pre-sorted constant is
simpler than recomputing, and the registered-global list in the
ESLint config is the only extra surface.
2. Enable npm cache in CI.
All three jobs (validate, build, test) run `npm ci` in parallel. With
`cache: 'npm'` on actions/setup-node@v4, the second and third jobs
hit the cache and skip the cold install — saves ~60-120s per PR run.
3. Tighten two verbose comment blocks.
- selectors.js: the "defensive selectors" preamble said the same
thing three times. Compressed to 3 lines.
- constants.js: the FLASHCARD_COURSE_MAP docblock over-explained the
longest-match semantics; trimmed to 6 lines with an explicit note
that keys are hyphenated slugs and values are camelCase deck names.
No behavior change. Tests 309/309 pass; lint, prettier, selectors,
dicts, sync, glossary, validate, firefox build, bundle build all green
locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three targeted wins from `/simplify`. Net +19/-23 lines. Each item only landed after triaging for value — the review also flagged a CI composite-action extraction and a selector flatten, both skipped as over-engineering vs. real cost.
1. Pre-sort `FLASHCARD_COURSE_MAP` once at module load
`Object.entries(map).sort((a,b) => b[0].length - a[0].length)` was running inside the per-URL course resolver in both content.js:320 and sidebar-chat.js:868. Map has ~30 entries so it's not a real hot path, but a pre-sorted `FLASHCARD_COURSE_SLUGS_SORTED` constant is strictly simpler than recomputing. Added to the ESLint global list alongside `FLASHCARD_COURSE_MAP`.
2. Enable npm cache in CI
`validate`, `build`, `test` all run `npm ci` in parallel. With `cache: 'npm'` on `actions/setup-node@v4`, the 2nd and 3rd jobs hit the warm cache and skip the cold install. Expected saving ~60–120s per PR run.
3. Tighten two comment blocks
Findings that were deliberately skipped
Verification (local)
Test plan
🤖 Generated with Claude Code