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" &&
|
||||
|
||||
@@ -91,6 +91,13 @@ export default function CropZoningWrapper() {
|
||||
>,
|
||||
completedTaskMessage?: string,
|
||||
) => {
|
||||
console.log("[crop-zoning][wrapper][first-page]", {
|
||||
sensorUuid: sensorHub.id,
|
||||
pagination: firstResponse.pagination ?? null,
|
||||
zonesCount: firstResponse.zones?.length ?? 0,
|
||||
taskStatus: firstResponse.task?.status ?? null,
|
||||
});
|
||||
|
||||
setAreaGeoJson(firstResponse.area as unknown as MapDrawGeoJSON);
|
||||
|
||||
const firstPageZones = firstResponse.zones ?? [];
|
||||
@@ -107,6 +114,13 @@ export default function CropZoningWrapper() {
|
||||
for (let page = 2; page <= totalPages; page++) {
|
||||
if (cancelled) break;
|
||||
|
||||
console.log("[crop-zoning][wrapper][fetch-page]", {
|
||||
sensorUuid: sensorHub.id,
|
||||
page,
|
||||
pageSize,
|
||||
totalPages,
|
||||
});
|
||||
|
||||
const pageRes = await cropZoningService.getArea(sensorHub.id, {
|
||||
page,
|
||||
pageSize,
|
||||
@@ -116,6 +130,14 @@ export default function CropZoningWrapper() {
|
||||
throw new Error(t("errors.areaLoadFailed"));
|
||||
}
|
||||
|
||||
console.log("[crop-zoning][wrapper][page-response]", {
|
||||
sensorUuid: sensorHub.id,
|
||||
page,
|
||||
pagination: pageRes.pagination ?? null,
|
||||
zonesCount: pageRes.zones?.length ?? 0,
|
||||
taskStatus: pageRes.task?.status ?? null,
|
||||
});
|
||||
|
||||
zonePages.push(pageRes.zones ?? []);
|
||||
|
||||
const mergedZones = mergeZones(zonePages);
|
||||
@@ -140,6 +162,12 @@ export default function CropZoningWrapper() {
|
||||
};
|
||||
|
||||
while (!cancelled && polls < MAX_POLLS) {
|
||||
console.log("[crop-zoning][wrapper][poll]", {
|
||||
sensorUuid: sensorHub.id,
|
||||
pollAttempt: polls + 1,
|
||||
pageSize: ZONES_PAGE_SIZE,
|
||||
});
|
||||
|
||||
const res = await cropZoningService.getArea(sensorHub.id, {
|
||||
page: 1,
|
||||
pageSize: ZONES_PAGE_SIZE,
|
||||
@@ -150,6 +178,15 @@ export default function CropZoningWrapper() {
|
||||
const task = res.task;
|
||||
const taskStatus = getNormalizedTaskStatus(task?.status);
|
||||
|
||||
console.log("[crop-zoning][wrapper][poll-response]", {
|
||||
sensorUuid: sensorHub.id,
|
||||
pollAttempt: polls + 1,
|
||||
taskStatus: task?.status ?? null,
|
||||
pagination: res.pagination ?? null,
|
||||
zonesCount: res.zones?.length ?? 0,
|
||||
hasArea: Boolean(res.area),
|
||||
});
|
||||
|
||||
if (task) {
|
||||
setProgress({
|
||||
message: task.message || task.stage_label || t("loadingArea"),
|
||||
|
||||
Reference in New Issue
Block a user