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 = {
|
export const cropZoningService = {
|
||||||
getProducts(): Promise<{ products: Product[] }> {
|
getProducts(): Promise<{ products: Product[] }> {
|
||||||
return unwrap(
|
return unwrap(
|
||||||
@@ -322,6 +331,14 @@ export const cropZoningService = {
|
|||||||
const cached = readCachedArea(sensorUuid, page, pageSize);
|
const cached = readCachedArea(sensorUuid, page, pageSize);
|
||||||
|
|
||||||
if (cached) {
|
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);
|
return Promise.resolve(cached);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,18 +348,42 @@ export const cropZoningService = {
|
|||||||
params.set("page", String(page));
|
params.set("page", String(page));
|
||||||
params.set("page_size", String(pageSize));
|
params.set("page_size", String(pageSize));
|
||||||
|
|
||||||
|
const endpoint = `${PREFIX}/area/?${params.toString()}`;
|
||||||
|
|
||||||
|
logAreaRequest("request", {
|
||||||
|
sensorUuid,
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
endpoint,
|
||||||
|
});
|
||||||
|
|
||||||
return unwrap(
|
return unwrap(
|
||||||
apiClient.get<ApiResponse<CropZoningAreaResponse>>(
|
apiClient.get<ApiResponse<CropZoningAreaResponse>>(endpoint),
|
||||||
`${PREFIX}/area/?${params.toString()}`,
|
|
||||||
),
|
|
||||||
).then((response) => {
|
).then((response) => {
|
||||||
if ("task_id" in response) {
|
if ("task_id" in response) {
|
||||||
|
logAreaRequest("response", {
|
||||||
|
sensorUuid,
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
taskId: response.task_id,
|
||||||
|
status: response.status,
|
||||||
|
});
|
||||||
return normalizeTaskInitResponse(response);
|
return normalizeTaskInitResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalized = normalizeAreaResult(response);
|
const normalized = normalizeAreaResult(response);
|
||||||
const taskStatus = normalized.task?.status?.toLowerCase();
|
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 (
|
if (
|
||||||
normalized.area &&
|
normalized.area &&
|
||||||
taskStatus !== "pending" &&
|
taskStatus !== "pending" &&
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ export default function CropZoningWrapper() {
|
|||||||
>,
|
>,
|
||||||
completedTaskMessage?: string,
|
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);
|
setAreaGeoJson(firstResponse.area as unknown as MapDrawGeoJSON);
|
||||||
|
|
||||||
const firstPageZones = firstResponse.zones ?? [];
|
const firstPageZones = firstResponse.zones ?? [];
|
||||||
@@ -107,6 +114,13 @@ export default function CropZoningWrapper() {
|
|||||||
for (let page = 2; page <= totalPages; page++) {
|
for (let page = 2; page <= totalPages; page++) {
|
||||||
if (cancelled) break;
|
if (cancelled) break;
|
||||||
|
|
||||||
|
console.log("[crop-zoning][wrapper][fetch-page]", {
|
||||||
|
sensorUuid: sensorHub.id,
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
totalPages,
|
||||||
|
});
|
||||||
|
|
||||||
const pageRes = await cropZoningService.getArea(sensorHub.id, {
|
const pageRes = await cropZoningService.getArea(sensorHub.id, {
|
||||||
page,
|
page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -116,6 +130,14 @@ export default function CropZoningWrapper() {
|
|||||||
throw new Error(t("errors.areaLoadFailed"));
|
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 ?? []);
|
zonePages.push(pageRes.zones ?? []);
|
||||||
|
|
||||||
const mergedZones = mergeZones(zonePages);
|
const mergedZones = mergeZones(zonePages);
|
||||||
@@ -140,6 +162,12 @@ export default function CropZoningWrapper() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
while (!cancelled && polls < MAX_POLLS) {
|
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, {
|
const res = await cropZoningService.getArea(sensorHub.id, {
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: ZONES_PAGE_SIZE,
|
pageSize: ZONES_PAGE_SIZE,
|
||||||
@@ -150,6 +178,15 @@ export default function CropZoningWrapper() {
|
|||||||
const task = res.task;
|
const task = res.task;
|
||||||
const taskStatus = getNormalizedTaskStatus(task?.status);
|
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) {
|
if (task) {
|
||||||
setProgress({
|
setProgress({
|
||||||
message: task.message || task.stage_label || t("loadingArea"),
|
message: task.message || task.stage_label || t("loadingArea"),
|
||||||
|
|||||||
Reference in New Issue
Block a user