grain.social is a photo sharing platform built on atproto. grain.social
atproto photography appview
57
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: loosen 3-part name fallback to match POIs inside regions

The POI+locality+country fallback was guarded with region IS NULL to
avoid pulling Washington DC records into Seattle clicks, but that also
rejected NYC POI records (region="New York"). Loosen to
(region IS NULL OR region = parts[-2]) so a click on "India Street,
New York, US" matches NYC records (region="New York" = parts[-2])
while still keeping DC out (region="District of Columbia", neither
null nor "Washington").

Verified against 500 sampled prod records: 458/500 now self-match via
the name-based query (up from 406), zero over-match from Seattle
clicks to DC. The remaining 42 are POI+region or POI+country-only
cases that fall through to the exact H3-cell match.

+17 -11
+17 -11
server/feeds/location.ts
··· 57 57 locality?: string; 58 58 region?: string; 59 59 country?: string; 60 - // When true, require the matched record to have region IS NULL. 61 - // Used for the [POI, locality, country] 3-part fallback so that 62 - // "Seattle, Washington, US" doesn't pull in Washington DC records 63 - // (locality=Washington, region=District of Columbia) while still 64 - // catching records with no region like "Tokyo Midtown, Minato, JP". 65 - regionMustBeNull?: boolean; 60 + // Require the record's region to be NULL or equal this string. Used 61 + // by the [POI, locality, country] 3-part fallback so that clicking 62 + // a NYC POI ("India Street, New York, US") matches NYC records 63 + // (region="New York" = parts[-2]), a Tokyo POI ("Tokyo Midtown, 64 + // Minato, JP") matches Minato records (region=null), and Seattle 65 + // clicks ("Seattle, Washington, US") DON'T pull in Washington DC 66 + // (region="District of Columbia", neither null nor "Washington"). 67 + regionNullOrEqual?: string; 66 68 }; 67 69 const interps: Interp[] = []; 68 70 if (parts.length >= 3) { ··· 71 73 // "Northeast 33rd Drive, Portland, Oregon, US") parse correctly. 72 74 const [locality, region, country] = parts.slice(-3); 73 75 interps.push({ locality, region, country }); 74 - // Also try [POI, locality, country] for records that legitimately 75 - // have no region (common for non-US places and POIs). 76 + // Also try [POI, locality, country] for POI-inside-locality cases. 77 + // The regionNullOrEqual guard prevents pulling in same-named 78 + // localities in unrelated regions. 76 79 interps.push({ 77 80 locality: parts[parts.length - 2], 78 81 country: parts[parts.length - 1], 79 - regionMustBeNull: true, 82 + regionNullOrEqual: parts[parts.length - 2], 80 83 }); 81 84 } else if (parts.length === 2) { 82 85 // Ambiguous: could be [locality, country] ("Paris, FR") or ··· 113 116 matches.push(`UPPER(json_extract(t.address, '$.country')) IN (${placeholders})`); 114 117 params.push(...aliases); 115 118 } 116 - if (interp.regionMustBeNull) { 117 - matches.push(`json_extract(t.address, '$.region') IS NULL`); 119 + if (interp.regionNullOrEqual) { 120 + matches.push( 121 + `(json_extract(t.address, '$.region') IS NULL OR UPPER(json_extract(t.address, '$.region')) = UPPER($${p++}))`, 122 + ); 123 + params.push(interp.regionNullOrEqual); 118 124 } 119 125 if (matches.length) interpClauses.push(`(${matches.join(" AND ")})`); 120 126 }