oliver-zehentleitner / maity
clean-up: hub shared helpers: one If-None-Match check, one chunks(), one base64url/cursor codec, ignoring_duplicates in db.py
tsk-k25qqhygend8 Open
From the clean-up audit tsk-hgnbapyw7hnh, the cross-area findings (areas 10-17) that the per-area cards left to one shared card. Read at main 80647565; every line number is at that SHA, so check it against current main first. Four small, low-risk helpers. The two items that touch threads and row locks (the copied Worker class, insert-then-lock) are on a sibling card filed at the same time.
Order:
- Item 1: tsk-vvyqmk9vwg8e (in progress, versioned avatar URLs) changes routes/avatars.py caching. Rebase on it. tsk-tnetc5fgr7pm item 4 merges the
public, max-age=60constants in the same files (public_pages.py, routes/badges.py, landing.py:811). Do both in one PR, or this one after it. - Item 3: tsk-8vdegd61y70v item 4 rewrites the key handling in notifications/positions.py. Do the codec swap there after it.
- Item 4: tsk-8vdegd61y70v item 7 builds the shared chat read mark on
listing.ignoring_duplicates. Move the helper first, or let item 7 import it from its new place.
1. The If-None-Match check is written 7 times, and landing.cached_json gets it wrong (duplication, small bug)
- Inline copies of "
*or the tag, weak tags compared by value": - public_pages.py:160, :195, :244 (three in one file)
- landing_files.py:136-138
- routes/badges.py:57-58
- The same rule as private functions:
- routes/contract_text.py:58
_matches - routes/keep_the_why.py:61
_matches - routes/project_images.py:27
_matches, which routes/attachments.py:34 (used :296) and routes/avatars.py:24 (used :44) import although it is private. landing.cached_json(landing.py:806-818) compares by exact string only (:814-816). It never answers304toIf-None-Match: *or to a weak tag (W/"…"), unlike every copy above.- Proposal: a public
http_cache.not_modified(request, etag) -> bool(or in an existing module such asshell.pyorviews.py), used by all of the above,cached_jsonincluded. - Effort: S. Risk: low.
cached_jsonstarts answering 304 to*and to weak tags, which RFC 9110 §13.1.2 asks for anyway.
2. Three _chunks helpers for IN lists (duplication)
- Files: export.py:107 (generator, size
CHUNK), loadtest.py:260 (list of lists), conversation_list.py:67 (generator). The same slicing is written inline at board/links.py:386. routes/seo.py:106chunkssplits sitemap entries, which is a different purpose; leave it unless it fits. - Proposal: one
db.chunks(values, size). The callers pass their own size, because the IN-list limits differ per caller. - Effort: S. Risk: none.
3. base64url without padding, and JSON cursors, hand-rolled beside paging._encode/_decode (duplication)
- The generic pair already exists: paging.py:25
_encodeand :29_decode(JSON, then base64url without=). Copies: - notifications/tokens.py:19 and :23 (bytes)
- notifications/positions.py:92 and :97 (bytes)
- notifications/listing.py:334 and :339 (a JSON cursor)
- routes/requests.py:1028 and :1042 (a JSON cursor, inline)
- routes/ticker.py:244 and :250 (a JSON cursor)
- auth/passwords.py:20 and :24 (bytes)
- github_app.py:80 and :231 (bytes, JWT parts)
- auth/credentials.py:37 (encode only)
- Proposal: make paging's pair public (
paging.encode_cursor/decode_cursor) for the JSON cursors, and addb64url(bytes) -> str/unb64url(str) -> bytesbeside them for the byte cases. Each caller keeps its own error mapping (a bad cursor isinvalidwith its field). - Effort: S. Risk: low. The output must stay byte-identical: positions and tokens are stored or mailed, and cursors are held by clients.
4. listing.ignoring_duplicates belongs in db.py (design)
- File: notifications/listing.py:402-409. It is an INSERT that ignores a duplicate key on PostgreSQL, SQLite and MariaDB. It is used at listing.py:395 and :438.
- Other sites write the PostgreSQL-only form
postgresql.insert(...).on_conflict_do_nothing()by hand: auth/nonces.py:48 and :66, listening.py:275, worker_runs.py:56, jourfixe/rounds.py:189. These run on PostgreSQL only today (replicas), but nothing in the code says so where they are called. - Proposal: move it to
db.insert_ignoring_duplicates(conn, table)and use it at all seven sites. Keep.returning(...)where a caller needs it (nonces, worker_runs); MariaDB has no RETURNING on INSERT IGNORE, so either keep those two PostgreSQL-only and say why, or document the limit on the helper. - Effort: S. Risk: low.
Left out as duplicates: none. Searched: If-None-Match, cached_json, _chunks, urlsafe_b64, ignoring_duplicates, on_conflict_do_nothing. tsk-tnetc5fgr7pm and tsk-8vdegd61y70v left items 1 and 4 to this card on purpose.
Correction to the audit's count: "If-None-Match copied 9 times" counts routes/attachments.py and routes/avatars.py, which import project_images._matches rather than copy it. There are 7 copies plus 2 imports of a private function.
Effort sum: S+S+S+S = 4 points.
Notes
Maity Coder Claude 003 · Nov 13, 2026, 23:12 UTC
More sites from the clean-up audit (tsk-hgnbapyw7hnh, uncovered-files pass at 9dfd4b65):
routes/contract_text.py:58routes/requests.py:1028,:1042: the cursor encode and decode pairroutes/keep_the_why.py:61_matches