Geo Stage 4 (server): home-aware feed sectioning (Near you / country / world)

Completes the server side of "Closer to Home". /api/feed gains a `home` param
('US' or 'US-NY'); when set the response is private (like prefs) and sectioned:

- Near you (+ Elsewhere in your country when a state is set) is a ONE-TIME lead
  block on page 0; the world is the paginated body. next_offset tells the client
  where to continue, so the lead block never skews world paging.
- Thin tiers fold down (MIN_TIER=3) so a header is never shown empty (lead, don't trap).
- State match counts only on high/medium geo confidence; the "country" tier excludes
  exactly what went to "near", so a low-confidence home-state story still surfaces
  (it doesn't vanish between tiers — caught + tested).
- Items carry a `section` tag; paywalled sort is now within-section. No home => exact
  prior behavior (section null, default/edge-cached feed unchanged), Brief untouched.

364 tests green. Frontend next: Home picker + sectioned feed rendering.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jay
2026-06-19 19:35:22 -04:00
parent ad4e88c8f2
commit e7e8f5515e
3 changed files with 165 additions and 19 deletions
+8 -3
View File
@@ -182,9 +182,14 @@ def feed(
elif geo_scope == "country" and home_country:
clauses.append("EXISTS (SELECT 1 FROM article_places p WHERE p.article_id = a.id AND p.country_code = ?)")
params.append(home_country)
if home_state: # "elsewhere in your country" = your country, but not your state
clauses.append("NOT EXISTS (SELECT 1 FROM article_places p2 WHERE p2.article_id = a.id AND p2.state_code = ?)")
params.append(home_state)
if home_state:
# "elsewhere in your country" excludes ONLY what actually went to "near" (a
# high/medium-confidence home-state match). A low-confidence home-state story
# isn't near, so it must still surface here, not vanish between tiers.
clauses.append(
"NOT (g.confidence IN ('high','medium') AND EXISTS (SELECT 1 FROM article_places p2 "
"WHERE p2.article_id = a.id AND p2.country_code = ? AND p2.state_code = ?))")
params.extend([home_country, home_state])
elif geo_scope == "world" and home_country:
clauses.append("NOT EXISTS (SELECT 1 FROM article_places p WHERE p.article_id = a.id AND p.country_code = ?)")
params.append(home_country)