@adventurelabs/scout-core 1.0.61 → 1.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/helpers/herds.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IHerd } from "../types/db";
|
|
2
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
3
3
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
4
|
-
import {
|
|
4
|
+
import { IHerdModulesResponseWithStatus } from "../types/herd_module";
|
|
5
5
|
export declare function get_herds(client: SupabaseClient): Promise<IWebResponseCompatible<IHerd[]>>;
|
|
6
6
|
export declare function get_herd_by_slug(slug: string): Promise<IWebResponseCompatible<IHerd>>;
|
|
7
7
|
export declare function deleteHerd(herd_id: number): Promise<IWebResponseCompatible<boolean>>;
|
|
8
8
|
export declare function createHerd(newHerd: any): Promise<IWebResponseCompatible<boolean>>;
|
|
9
|
-
export declare function server_load_herd_modules(): Promise<
|
|
9
|
+
export declare function server_load_herd_modules(): Promise<IHerdModulesResponseWithStatus>;
|
package/dist/helpers/herds.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
3
|
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
4
|
-
import { HerdModule } from "../types/herd_module";
|
|
4
|
+
import { HerdModule, } from "../types/herd_module";
|
|
5
5
|
export async function get_herds(client) {
|
|
6
6
|
const { data: herds } = await client.from("herds").select();
|
|
7
7
|
if (!herds) {
|
|
@@ -70,7 +70,14 @@ export async function server_load_herd_modules() {
|
|
|
70
70
|
const client_supabase = await newServerClient();
|
|
71
71
|
let new_herds = await get_herds(client_supabase);
|
|
72
72
|
if (new_herds.status != EnumWebResponse.SUCCESS || !new_herds.data) {
|
|
73
|
-
return
|
|
73
|
+
return {
|
|
74
|
+
status: EnumWebResponse.ERROR,
|
|
75
|
+
msg: "No herds found",
|
|
76
|
+
data: null,
|
|
77
|
+
time_finished: Date.now(),
|
|
78
|
+
time_sent: Date.now(),
|
|
79
|
+
server_processing_time_ms: Date.now() - startTime,
|
|
80
|
+
};
|
|
74
81
|
}
|
|
75
82
|
console.log(`[server_load_herd_modules] Loading ${new_herds.data.length} herds in parallel...`);
|
|
76
83
|
let new_herd_modules = [];
|
|
@@ -81,5 +88,14 @@ export async function server_load_herd_modules() {
|
|
|
81
88
|
const endTime = Date.now();
|
|
82
89
|
const totalLoadTime = endTime - startTime;
|
|
83
90
|
console.log(`[server_load_herd_modules] Loaded ${new_herds.data.length} herds in ${totalLoadTime}ms (parallel processing)`);
|
|
84
|
-
|
|
91
|
+
// Record the time when we're about to send the response
|
|
92
|
+
const timeSent = Date.now();
|
|
93
|
+
return {
|
|
94
|
+
status: EnumWebResponse.SUCCESS,
|
|
95
|
+
msg: "Herd modules loaded successfully",
|
|
96
|
+
data: serialized_herd_modules,
|
|
97
|
+
time_finished: endTime,
|
|
98
|
+
time_sent: timeSent,
|
|
99
|
+
server_processing_time_ms: totalLoadTime,
|
|
100
|
+
};
|
|
85
101
|
}
|
|
@@ -4,6 +4,7 @@ import { EnumScoutStateStatus, setActiveHerdId, setHerdModules, setStatus, setHe
|
|
|
4
4
|
import { EnumHerdModulesLoadingState } from "../types/herd_module";
|
|
5
5
|
import { server_load_herd_modules } from "../helpers/herds";
|
|
6
6
|
import { server_get_user } from "../helpers/users";
|
|
7
|
+
import { EnumWebResponse } from "../types/requests";
|
|
7
8
|
/**
|
|
8
9
|
* Hook for refreshing scout data with detailed timing measurements
|
|
9
10
|
*
|
|
@@ -72,10 +73,47 @@ export function useScoutRefresh(options = {}) {
|
|
|
72
73
|
const parallelDuration = Date.now() - parallelStartTime;
|
|
73
74
|
console.log(`[useScoutRefresh] Parallel API requests completed in ${parallelDuration}ms`);
|
|
74
75
|
// Extract results and timing
|
|
75
|
-
const
|
|
76
|
+
const herdModulesResponse = herdModulesResult.result;
|
|
76
77
|
const res_new_user = userResult.result;
|
|
77
78
|
const herdModulesDuration = herdModulesResult.duration;
|
|
78
79
|
const userApiDuration = userResult.duration;
|
|
80
|
+
// Calculate network latency for herd modules
|
|
81
|
+
let networkLatencyMs = 0;
|
|
82
|
+
if (herdModulesResponse.status === EnumWebResponse.SUCCESS &&
|
|
83
|
+
herdModulesResponse.data) {
|
|
84
|
+
const serverFinishTime = herdModulesResponse.time_finished;
|
|
85
|
+
const serverSentTime = herdModulesResponse.time_sent;
|
|
86
|
+
const clientReceiveTime = Date.now();
|
|
87
|
+
// More accurate network latency: from when server sent to when client received
|
|
88
|
+
const estimatedNetworkLatency = clientReceiveTime - serverSentTime;
|
|
89
|
+
networkLatencyMs = Math.max(0, estimatedNetworkLatency);
|
|
90
|
+
// Time between server finishing processing and sending response
|
|
91
|
+
const serverOverhead = serverSentTime - serverFinishTime;
|
|
92
|
+
console.log(`[useScoutRefresh] Network latency calculation:`);
|
|
93
|
+
console.log(` - Server finished processing at: ${new Date(serverFinishTime).toISOString()}`);
|
|
94
|
+
console.log(` - Server sent response at: ${new Date(serverSentTime).toISOString()}`);
|
|
95
|
+
console.log(` - Client received at: ${new Date(clientReceiveTime).toISOString()}`);
|
|
96
|
+
console.log(` - Server processing time: ${herdModulesResponse.server_processing_time_ms}ms`);
|
|
97
|
+
console.log(` - Server overhead (finish to send): ${serverOverhead}ms`);
|
|
98
|
+
console.log(` - Estimated network latency: ${networkLatencyMs}ms`);
|
|
99
|
+
console.log(` - Client total time: ${herdModulesDuration}ms`);
|
|
100
|
+
console.log(` - Breakdown: ${herdModulesResponse.server_processing_time_ms}ms (server) + ${serverOverhead}ms (overhead) + ${networkLatencyMs}ms (network) = ${herdModulesResponse.server_processing_time_ms +
|
|
101
|
+
serverOverhead +
|
|
102
|
+
networkLatencyMs}ms`);
|
|
103
|
+
// Additional analysis
|
|
104
|
+
if (herdModulesResponse.data.length > 0) {
|
|
105
|
+
const totalDevices = herdModulesResponse.data.reduce((sum, hm) => sum + (hm.devices?.length || 0), 0);
|
|
106
|
+
const totalEvents = herdModulesResponse.data.reduce((sum, hm) => sum + (hm.events?.length || 0), 0);
|
|
107
|
+
console.log(` - Response size analysis:`);
|
|
108
|
+
console.log(` * Herds: ${herdModulesResponse.data.length}`);
|
|
109
|
+
console.log(` * Total devices: ${totalDevices}`);
|
|
110
|
+
console.log(` * Total events: ${totalEvents}`);
|
|
111
|
+
console.log(` * Estimated payload: ~${Math.round((herdModulesResponse.data.length * 2 +
|
|
112
|
+
totalDevices * 3 +
|
|
113
|
+
totalEvents * 5) /
|
|
114
|
+
1024)}KB`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
79
117
|
// Store timing values
|
|
80
118
|
timingRefs.current.herdModulesDuration = herdModulesDuration;
|
|
81
119
|
timingRefs.current.userApiDuration = userApiDuration;
|
|
@@ -90,14 +128,22 @@ export function useScoutRefresh(options = {}) {
|
|
|
90
128
|
console.log(` - User API: ${userApiDuration}ms (server processing + network)`);
|
|
91
129
|
console.log(` - Parallel execution: ${parallelDuration}ms`);
|
|
92
130
|
console.log(` - Network overhead: ${networkOverhead}ms`);
|
|
131
|
+
if (networkLatencyMs > 0) {
|
|
132
|
+
console.log(` - Estimated network latency: ${networkLatencyMs}ms`);
|
|
133
|
+
}
|
|
93
134
|
// Validate API responses
|
|
94
|
-
|
|
95
|
-
|
|
135
|
+
const validationStartTime = Date.now();
|
|
136
|
+
if (!herdModulesResponse.data ||
|
|
137
|
+
!Array.isArray(herdModulesResponse.data)) {
|
|
96
138
|
throw new Error("Invalid herd modules response");
|
|
97
139
|
}
|
|
98
140
|
if (!res_new_user || !res_new_user.data) {
|
|
99
141
|
throw new Error("Invalid user response");
|
|
100
142
|
}
|
|
143
|
+
const validationDuration = Date.now() - validationStartTime;
|
|
144
|
+
console.log(`[useScoutRefresh] Data validation took: ${validationDuration}ms`);
|
|
145
|
+
// Use the validated data
|
|
146
|
+
const compatible_new_herd_modules = herdModulesResponse.data;
|
|
101
147
|
// Measure data processing duration
|
|
102
148
|
const dataProcessingStartTime = Date.now();
|
|
103
149
|
dispatch(setHerdModules(compatible_new_herd_modules));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
2
|
import { IDevice, IEventWithTags, IHerd, IPlan, ILayer, IUserAndRole, IZoneWithActions, ISessionWithCoordinates } from "../types/db";
|
|
3
|
+
import { EnumWebResponse } from "./requests";
|
|
3
4
|
export declare enum EnumHerdModulesLoadingState {
|
|
4
5
|
NOT_LOADING = "NOT_LOADING",
|
|
5
6
|
LOADING = "LOADING",
|
|
@@ -39,3 +40,16 @@ export interface IHerdModule {
|
|
|
39
40
|
sessions: ISessionWithCoordinates[];
|
|
40
41
|
layers: ILayer[];
|
|
41
42
|
}
|
|
43
|
+
export interface IHerdModulesResponse {
|
|
44
|
+
data: IHerdModule[];
|
|
45
|
+
time_finished: number;
|
|
46
|
+
server_processing_time_ms: number;
|
|
47
|
+
}
|
|
48
|
+
export interface IHerdModulesResponseWithStatus {
|
|
49
|
+
status: EnumWebResponse;
|
|
50
|
+
msg: string;
|
|
51
|
+
data: IHerdModule[] | null;
|
|
52
|
+
time_finished: number;
|
|
53
|
+
time_sent: number;
|
|
54
|
+
server_processing_time_ms: number;
|
|
55
|
+
}
|