feat(web): include_synsets option on forms-for-synsets batch [SIGN-640] - #6
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe synset form lookup now associates each form with matching synset IDs. The forms endpoint accepts ChangesSynset form mapping
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
wn/web.py (1)
419-423: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueGuarantee deterministic ordering of the API response.
Because dictionaries preserve insertion order, the sequence in which rows are yielded by SQLite dictates the order of keys in the response when
include_synsets=True. Additionally, if a single form expresses multiple synsets, the order ofsynset_ids in its corresponding list will also depend on the query's return order.Consider appending an
ORDER BY f.form, ss.idclause to the SQL query to guarantee a deterministic API response, which helps prevent flaky tests and unpredictable client-side behavior.♻️ Proposed refactor
Apply this change immediately above the mapping block:
if not with_entities: query += ' AND f.form = LOWER(f.form)' + + query += ' ORDER BY f.form, ss.id' mapping: dict[str, list[str]] = {}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@wn/web.py` around lines 419 - 423, Update the SQL query used immediately before the mapping construction to order rows by form and synset ID using ORDER BY f.form, ss.id. Keep the existing mapping logic unchanged so both dictionary key order and each form’s synset_id list are deterministic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@wn/web.py`:
- Around line 419-423: Update the SQL query used immediately before the mapping
construction to order rows by form and synset ID using ORDER BY f.form, ss.id.
Keep the existing mapping logic unchanged so both dictionary key order and each
form’s synset_id list are deterministic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a5d1ce94-f960-4b29-b785-0eab16d72f9d
📒 Files selected for processing (2)
tests/web_test.pywn/web.py
PR 2 of 3 for SIGN-640: the dictionary sitemap should emit
<lastmod>.What
POST /lexicons/{lexicon}/formsgains an optional body flag:{ "synsets": ["test-en-0001-n", "test-en-0006-n"], "include_synsets": true } → { "data": { "information": ["test-en-0001-n"], "datum": ["test-en-0006-n"], "data": ["test-en-0006-n"] }, "meta": { "total": 3 } }A word page's lastmod is the max over its signed synsets' change timestamps (which come from dictionary-api, sign/dictionary-api#73) — so the batch must say which synsets matched each form. Without the flag the response is the flat sorted form list, unchanged for existing callers.
Internally the query now selects
(form, synset_id)pairs and both response shapes derive from one mapping — no second query path.Tests
16 web tests pass (new: the map shape, including a secondary written form inheriting its entry's synsets). ruff, mypy, build, full suite (157) green.
🤖 Generated with Claude Code
Note
Low Risk
Backward-compatible optional response shape on a batch read endpoint; default behavior unchanged for existing clients.
Overview
Adds optional
include_synsetsonPOST /lexicons/{lexicon}/formsso batch callers can see which synset IDs each matched form expresses—needed to compute per-word lastmod from synset change timestamps (SIGN-640)._get_forms_for_synsetsnow returns aform → [synset_id, …]map built from a single query that selects(form, synset_id)pairs instead of distinct forms only. The handler still returns the flat sorted form list wheninclude_synsetsis omitted or false; withinclude_synsets: true,datais that map andmeta.totalstays the form count.A web test covers the map shape, including a secondary written form (
data) tied to the same synset as its entry.Reviewed by Cursor Bugbot for commit c588e7c. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
New Features
Bug Fixes