UPDATE
This commit is contained in:
@@ -281,6 +281,15 @@ function writeCachedArea(
|
||||
}
|
||||
}
|
||||
|
||||
function logAreaRequest(
|
||||
phase: "cache-hit" | "request" | "response",
|
||||
payload: Record<string, unknown>,
|
||||
): void {
|
||||
if (typeof window === "undefined") return;
|
||||
|
||||
console.log(`[crop-zoning][area][${phase}]`, payload);
|
||||
}
|
||||
|
||||
export const cropZoningService = {
|
||||
getProducts(): Promise<{ products: Product[] }> {
|
||||
return unwrap(
|
||||
@@ -322,6 +331,14 @@ export const cropZoningService = {
|
||||
const cached = readCachedArea(sensorUuid, page, pageSize);
|
||||
|
||||
if (cached) {
|
||||
logAreaRequest("cache-hit", {
|
||||
sensorUuid,
|
||||
page,
|
||||
pageSize,
|
||||
pagination: cached.pagination ?? null,
|
||||
taskStatus: cached.task?.status ?? null,
|
||||
zonesCount: cached.zones?.length ?? 0,
|
||||
});
|
||||
return Promise.resolve(cached);
|
||||
}
|
||||
}
|
||||
@@ -331,18 +348,42 @@ export const cropZoningService = {
|
||||
params.set("page", String(page));
|
||||
params.set("page_size", String(pageSize));
|
||||
|
||||
const endpoint = `${PREFIX}/area/?${params.toString()}`;
|
||||
|
||||
logAreaRequest("request", {
|
||||
sensorUuid,
|
||||
page,
|
||||
pageSize,
|
||||
endpoint,
|
||||
});
|
||||
|
||||
return unwrap(
|
||||
apiClient.get<ApiResponse<CropZoningAreaResponse>>(
|
||||
`${PREFIX}/area/?${params.toString()}`,
|
||||
),
|
||||
apiClient.get<ApiResponse<CropZoningAreaResponse>>(endpoint),
|
||||
).then((response) => {
|
||||
if ("task_id" in response) {
|
||||
logAreaRequest("response", {
|
||||
sensorUuid,
|
||||
page,
|
||||
pageSize,
|
||||
taskId: response.task_id,
|
||||
status: response.status,
|
||||
});
|
||||
return normalizeTaskInitResponse(response);
|
||||
}
|
||||
|
||||
const normalized = normalizeAreaResult(response);
|
||||
const taskStatus = normalized.task?.status?.toLowerCase();
|
||||
|
||||
logAreaRequest("response", {
|
||||
sensorUuid,
|
||||
page,
|
||||
pageSize,
|
||||
taskStatus: normalized.task?.status ?? null,
|
||||
pagination: normalized.pagination ?? null,
|
||||
zonesCount: normalized.zones?.length ?? 0,
|
||||
hasArea: Boolean(normalized.area),
|
||||
});
|
||||
|
||||
if (
|
||||
normalized.area &&
|
||||
taskStatus !== "pending" &&
|
||||
|
||||
Reference in New Issue
Block a user