fix(custom-pois): invalidate canonical parcel-analyze + parcel-poi-score keys (#1241)
Some checks failed
Deploy / deploy (push) Blocked by required conditions
Deploy / changes (push) Successful in 8s
Deploy / build-backend (push) Has been skipped
Deploy / build-worker (push) Has been skipped
Deploy / build-frontend (push) Has been cancelled

useCustomPois mutations инвалидировали ['analyze', cad], а такой key
ни один useQuery не регистрирует. Canonical keys: ['parcel-analyze', cad,
horizon] и ['parcel-poi-score', cad]. Все 3 onSuccess были silent no-ops
→ скор+breakdown stale после правок кастомных POI.

Patch: analyzeKey → ['parcel-analyze', parcelCad] (prefix-only, TanStack
covers all horizons), добавлен poiScoreKey, оба инвалидируются вместе.
82/82 frontend тестов зелёные.

Closes #1241
This commit is contained in:
Light1YT 2026-06-13 12:47:18 +05:00 committed by bot-backend
parent 10df430cac
commit 01d00ec183

View file

@ -27,8 +27,20 @@ function customPoisKey(parcelCad?: string | null): unknown[] {
return ["custom-pois", parcelCad ?? null];
}
// Canonical analyze key prefix is ["parcel-analyze", cad, horizon] (see
// site-finder-api.ts `useParcelAnalyzeQuery`); invalidating with the
// prefix [parcel-analyze, cad] matches every horizon variant. Custom-POI
// add/update/delete also influences the standalone POI score endpoint
// ["parcel-poi-score", cad] (see `useParcelPoiScoreQuery`), so both must
// be invalidated to refresh score + breakdown after a mutation. The
// previous key ["analyze", cad] never matched any live useQuery — bug
// reference: issue #1241.
function analyzeKey(parcelCad: string): unknown[] {
return ["analyze", parcelCad];
return ["parcel-analyze", parcelCad];
}
function poiScoreKey(parcelCad: string): unknown[] {
return ["parcel-poi-score", parcelCad];
}
// ---------------------------------------------------------------------------
@ -56,7 +68,10 @@ export function useCustomPois(parcelCad?: string | null) {
}
/**
* Create a custom POI. Invalidates list + analyze query on success.
* Create a custom POI. On success invalidates:
* - ["custom-pois", parcelCad] (scoped list) + ["custom-pois", null] (global)
* - ["parcel-analyze", parcelCad] prefix (matches every horizon variant)
* - ["parcel-poi-score", parcelCad] (POI weighted score)
*/
export function useAddCustomPoi(parcelCad?: string | null) {
const queryClient = useQueryClient();
@ -75,6 +90,9 @@ export function useAddCustomPoi(parcelCad?: string | null) {
void queryClient.invalidateQueries({ queryKey: customPoisKey(null) });
if (parcelCad) {
void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) });
void queryClient.invalidateQueries({
queryKey: poiScoreKey(parcelCad),
});
}
},
});
@ -99,6 +117,9 @@ export function useUpdateCustomPoi(parcelCad?: string | null) {
void queryClient.invalidateQueries({ queryKey: customPoisKey(null) });
if (parcelCad) {
void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) });
void queryClient.invalidateQueries({
queryKey: poiScoreKey(parcelCad),
});
}
},
});
@ -122,6 +143,9 @@ export function useDeleteCustomPoi(parcelCad?: string | null) {
void queryClient.invalidateQueries({ queryKey: customPoisKey(null) });
if (parcelCad) {
void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) });
void queryClient.invalidateQueries({
queryKey: poiScoreKey(parcelCad),
});
}
},
});