@adventurelabs/scout-core 1.0.66 → 1.0.67
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.js +5 -39
- package/dist/hooks/useScoutRefresh.js +18 -50
- package/dist/supabase/server.js +1 -12
- package/package.json +1 -1
package/dist/helpers/herds.js
CHANGED
|
@@ -3,12 +3,7 @@ import { newServerClient } from "../supabase/server";
|
|
|
3
3
|
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
4
4
|
import { HerdModule, } from "../types/herd_module";
|
|
5
5
|
export async function get_herds(client) {
|
|
6
|
-
const queryStartTime = Date.now();
|
|
7
|
-
console.log(`[get_herds] Starting database query at ${new Date(queryStartTime).toISOString()}`);
|
|
8
6
|
const { data: herds } = await client.from("herds").select();
|
|
9
|
-
const queryEndTime = Date.now();
|
|
10
|
-
const queryDuration = queryEndTime - queryStartTime;
|
|
11
|
-
console.log(`[get_herds] Database query completed in ${queryDuration}ms`);
|
|
12
7
|
if (!herds) {
|
|
13
8
|
return {
|
|
14
9
|
status: EnumWebResponse.ERROR,
|
|
@@ -70,57 +65,28 @@ export async function createHerd(newHerd) {
|
|
|
70
65
|
}
|
|
71
66
|
}
|
|
72
67
|
export async function server_load_herd_modules() {
|
|
73
|
-
const requestReceivedTime = Date.now();
|
|
74
|
-
console.log(`[server_load_herd_modules] Request received at: ${new Date(requestReceivedTime).toISOString()}`);
|
|
75
68
|
const startTime = Date.now();
|
|
76
|
-
//
|
|
77
|
-
const supabaseStartTime = Date.now();
|
|
69
|
+
// load herds
|
|
78
70
|
const client_supabase = await newServerClient();
|
|
79
|
-
const supabaseTime = Date.now() - supabaseStartTime;
|
|
80
|
-
console.log(`[server_load_herd_modules] Supabase client creation took: ${supabaseTime}ms`);
|
|
81
|
-
// Measure database connection and initial query
|
|
82
|
-
const dbStartTime = Date.now();
|
|
83
71
|
let new_herds = await get_herds(client_supabase);
|
|
84
|
-
const dbConnectionTime = Date.now() - dbStartTime;
|
|
85
|
-
console.log(`[server_load_herd_modules] Database connection and initial herds query took: ${dbConnectionTime}ms`);
|
|
86
72
|
if (new_herds.status != EnumWebResponse.SUCCESS || !new_herds.data) {
|
|
87
|
-
const errorTime = Date.now();
|
|
88
73
|
return {
|
|
89
74
|
status: EnumWebResponse.ERROR,
|
|
90
75
|
msg: "No herds found",
|
|
91
76
|
data: null,
|
|
92
|
-
time_finished:
|
|
93
|
-
time_sent:
|
|
94
|
-
server_processing_time_ms:
|
|
77
|
+
time_finished: Date.now(),
|
|
78
|
+
time_sent: Date.now(),
|
|
79
|
+
server_processing_time_ms: Date.now() - startTime,
|
|
95
80
|
};
|
|
96
81
|
}
|
|
97
|
-
console.log(`[server_load_herd_modules] Loading ${new_herds.data.length} herds in parallel...`);
|
|
98
|
-
// Measure herd module creation
|
|
99
|
-
const herdModuleStartTime = Date.now();
|
|
100
82
|
let new_herd_modules = [];
|
|
101
83
|
const herdModulePromises = new_herds.data.map((herd) => HerdModule.from_herd(herd, client_supabase));
|
|
102
84
|
new_herd_modules = await Promise.all(herdModulePromises);
|
|
103
|
-
|
|
104
|
-
console.log(`[server_load_herd_modules] Herd module creation took: ${herdModuleTime}ms`);
|
|
105
|
-
// Measure serialization
|
|
106
|
-
const serializationStartTime = Date.now();
|
|
85
|
+
// now serialize the herd modules
|
|
107
86
|
let serialized_herd_modules = new_herd_modules.map((herd_module) => herd_module.to_serializable());
|
|
108
|
-
const serializationTime = Date.now() - serializationStartTime;
|
|
109
|
-
console.log(`[server_load_herd_modules] Serialization took: ${serializationTime}ms`);
|
|
110
87
|
const endTime = Date.now();
|
|
111
88
|
const totalLoadTime = endTime - startTime;
|
|
112
|
-
// Calculate detailed timing breakdown
|
|
113
|
-
const timeToClient = endTime - requestReceivedTime;
|
|
114
|
-
const processingTime = endTime - startTime;
|
|
115
89
|
console.log(`[server_load_herd_modules] Loaded ${new_herds.data.length} herds in ${totalLoadTime}ms (parallel processing)`);
|
|
116
|
-
console.log(`[server_load_herd_modules] Detailed timing breakdown:`);
|
|
117
|
-
console.log(` - Request received to start: ${startTime - requestReceivedTime}ms`);
|
|
118
|
-
console.log(` - Supabase client creation: ${supabaseTime}ms`);
|
|
119
|
-
console.log(` - Database connection & query: ${dbConnectionTime}ms`);
|
|
120
|
-
console.log(` - Herd module creation: ${herdModuleTime}ms`);
|
|
121
|
-
console.log(` - Serialization: ${serializationTime}ms`);
|
|
122
|
-
console.log(` - Total processing time: ${processingTime}ms`);
|
|
123
|
-
console.log(` - Total time to client: ${timeToClient}ms`);
|
|
124
90
|
// Record the time when we're about to send the response
|
|
125
91
|
const timeSent = Date.now();
|
|
126
92
|
return {
|
|
@@ -98,37 +98,13 @@ export function useScoutRefresh(options = {}) {
|
|
|
98
98
|
if (herdModulesResponse.status === EnumWebResponse.SUCCESS &&
|
|
99
99
|
herdModulesResponse.data) {
|
|
100
100
|
const serverFinishTime = herdModulesResponse.time_finished;
|
|
101
|
-
const serverSentTime = herdModulesResponse.time_sent;
|
|
102
101
|
const clientReceiveTime = Date.now();
|
|
103
|
-
|
|
104
|
-
const estimatedNetworkLatency = clientReceiveTime - serverSentTime;
|
|
102
|
+
const estimatedNetworkLatency = clientReceiveTime - serverFinishTime;
|
|
105
103
|
networkLatencyMs = Math.max(0, estimatedNetworkLatency);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
console.log(`
|
|
109
|
-
console.log(` -
|
|
110
|
-
console.log(` - Server sent response at: ${new Date(serverSentTime).toISOString()}`);
|
|
111
|
-
console.log(` - Client received at: ${new Date(clientReceiveTime).toISOString()}`);
|
|
112
|
-
console.log(` - Server processing time: ${herdModulesResponse.server_processing_time_ms}ms`);
|
|
113
|
-
console.log(` - Server overhead (finish to send): ${serverOverhead}ms`);
|
|
114
|
-
console.log(` - Estimated network latency: ${networkLatencyMs}ms`);
|
|
115
|
-
console.log(` - Client total time: ${herdModulesDuration}ms`);
|
|
116
|
-
console.log(` - Breakdown: ${herdModulesResponse.server_processing_time_ms}ms (server) + ${serverOverhead}ms (overhead) + ${networkLatencyMs}ms (network) = ${herdModulesResponse.server_processing_time_ms +
|
|
117
|
-
serverOverhead +
|
|
118
|
-
networkLatencyMs}ms`);
|
|
119
|
-
// Additional analysis
|
|
120
|
-
if (herdModulesResponse.data.length > 0) {
|
|
121
|
-
const totalDevices = herdModulesResponse.data.reduce((sum, hm) => sum + (hm.devices?.length || 0), 0);
|
|
122
|
-
const totalEvents = herdModulesResponse.data.reduce((sum, hm) => sum + (hm.events?.length || 0), 0);
|
|
123
|
-
console.log(` - Response size analysis:`);
|
|
124
|
-
console.log(` * Herds: ${herdModulesResponse.data.length}`);
|
|
125
|
-
console.log(` * Total devices: ${totalDevices}`);
|
|
126
|
-
console.log(` * Total events: ${totalEvents}`);
|
|
127
|
-
console.log(` * Estimated payload: ~${Math.round((herdModulesResponse.data.length * 2 +
|
|
128
|
-
totalDevices * 3 +
|
|
129
|
-
totalEvents * 5) /
|
|
130
|
-
1024)}KB`);
|
|
131
|
-
}
|
|
104
|
+
console.log(`[useScoutRefresh] Herd modules performance:`);
|
|
105
|
+
console.log(` - Server processing: ${herdModulesResponse.server_processing_time_ms}ms`);
|
|
106
|
+
console.log(` - Network latency: ${networkLatencyMs}ms`);
|
|
107
|
+
console.log(` - Total client time: ${herdModulesDuration}ms`);
|
|
132
108
|
}
|
|
133
109
|
// Store timing values
|
|
134
110
|
timingRefs.current.herdModulesDuration = herdModulesDuration;
|
|
@@ -139,14 +115,11 @@ export function useScoutRefresh(options = {}) {
|
|
|
139
115
|
// Calculate network overhead
|
|
140
116
|
const totalApiTime = herdModulesDuration + userApiDuration;
|
|
141
117
|
const networkOverhead = parallelDuration - Math.max(herdModulesDuration, userApiDuration);
|
|
142
|
-
console.log(`[useScoutRefresh] API
|
|
143
|
-
console.log(` - Herd modules: ${herdModulesDuration}ms
|
|
144
|
-
console.log(` - User API: ${userApiDuration}ms
|
|
118
|
+
console.log(`[useScoutRefresh] API performance:`);
|
|
119
|
+
console.log(` - Herd modules: ${herdModulesDuration}ms`);
|
|
120
|
+
console.log(` - User API: ${userApiDuration}ms`);
|
|
145
121
|
console.log(` - Parallel execution: ${parallelDuration}ms`);
|
|
146
|
-
console.log(` -
|
|
147
|
-
if (networkLatencyMs > 0) {
|
|
148
|
-
console.log(` - Estimated network latency: ${networkLatencyMs}ms`);
|
|
149
|
-
}
|
|
122
|
+
console.log(` - Time saved with parallel: ${totalApiTime - parallelDuration}ms`);
|
|
150
123
|
// Validate API responses
|
|
151
124
|
const validationStartTime = Date.now();
|
|
152
125
|
if (!herdModulesResponse.data ||
|
|
@@ -201,16 +174,13 @@ export function useScoutRefresh(options = {}) {
|
|
|
201
174
|
const loadingDuration = Date.now() - startTime;
|
|
202
175
|
dispatch(setHerdModulesLoadedInMs(loadingDuration));
|
|
203
176
|
dispatch(setStatus(EnumScoutStateStatus.DONE_LOADING));
|
|
204
|
-
// Log
|
|
205
|
-
console.log(
|
|
206
|
-
console.log(` -
|
|
177
|
+
// Log essential performance metrics
|
|
178
|
+
console.log(`[useScoutRefresh] Refresh completed successfully:`);
|
|
179
|
+
console.log(` - Total duration: ${loadingDuration}ms`);
|
|
180
|
+
console.log(` - Herd modules: ${herdModulesDuration}ms`);
|
|
207
181
|
console.log(` - User API: ${userApiDuration}ms`);
|
|
208
182
|
console.log(` - Parallel execution: ${parallelDuration}ms`);
|
|
209
|
-
console.log(` -
|
|
210
|
-
console.log(` - Data processing: ${dataProcessingDuration}ms`);
|
|
211
|
-
console.log(` - LocalStorage operations: ${localStorageDuration}ms`);
|
|
212
|
-
console.log(` - Total duration: ${loadingDuration}ms`);
|
|
213
|
-
console.log(` - Time saved with parallel execution: ${totalApiTime - parallelDuration}ms`);
|
|
183
|
+
console.log(` - Time saved with parallel: ${totalApiTime - parallelDuration}ms`);
|
|
214
184
|
onRefreshComplete?.();
|
|
215
185
|
}
|
|
216
186
|
catch (error) {
|
|
@@ -220,13 +190,11 @@ export function useScoutRefresh(options = {}) {
|
|
|
220
190
|
dispatch(setHerdModulesLoadingState(EnumHerdModulesLoadingState.UNSUCCESSFULLY_LOADED));
|
|
221
191
|
dispatch(setHerdModulesLoadedInMs(loadingDuration));
|
|
222
192
|
dispatch(setStatus(EnumScoutStateStatus.DONE_LOADING));
|
|
223
|
-
// Log
|
|
224
|
-
console.log(
|
|
225
|
-
console.log(` - Herd modules API: ${timingRefs.current.herdModulesDuration}ms`);
|
|
226
|
-
console.log(` - User API: ${timingRefs.current.userApiDuration}ms`);
|
|
227
|
-
console.log(` - Data processing: ${timingRefs.current.dataProcessingDuration}ms`);
|
|
228
|
-
console.log(` - LocalStorage operations: ${timingRefs.current.localStorageDuration}ms`);
|
|
193
|
+
// Log essential error metrics
|
|
194
|
+
console.log(`[useScoutRefresh] Refresh failed:`);
|
|
229
195
|
console.log(` - Total duration: ${loadingDuration}ms`);
|
|
196
|
+
console.log(` - Herd modules: ${timingRefs.current.herdModulesDuration}ms`);
|
|
197
|
+
console.log(` - User API: ${timingRefs.current.userApiDuration}ms`);
|
|
230
198
|
}
|
|
231
199
|
finally {
|
|
232
200
|
refreshInProgressRef.current = false;
|
package/dist/supabase/server.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { createServerClient } from "@supabase/ssr";
|
|
2
2
|
import { cookies } from "next/headers";
|
|
3
3
|
export async function newServerClient() {
|
|
4
|
-
const startTime = Date.now();
|
|
5
|
-
console.log(`[newServerClient] Starting client creation at ${new Date(startTime).toISOString()}`);
|
|
6
|
-
const cookieStartTime = Date.now();
|
|
7
4
|
const cookieStore = await cookies();
|
|
8
|
-
|
|
9
|
-
console.log(`[newServerClient] Cookie retrieval took: ${cookieTime}ms`);
|
|
10
|
-
const supabaseStartTime = Date.now();
|
|
11
|
-
const client = createServerClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY, {
|
|
5
|
+
return createServerClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY, {
|
|
12
6
|
cookies: {
|
|
13
7
|
getAll() {
|
|
14
8
|
return cookieStore.getAll();
|
|
@@ -25,9 +19,4 @@ export async function newServerClient() {
|
|
|
25
19
|
},
|
|
26
20
|
},
|
|
27
21
|
});
|
|
28
|
-
const supabaseTime = Date.now() - supabaseStartTime;
|
|
29
|
-
console.log(`[newServerClient] Supabase client creation took: ${supabaseTime}ms`);
|
|
30
|
-
const totalTime = Date.now() - startTime;
|
|
31
|
-
console.log(`[newServerClient] Total client creation time: ${totalTime}ms`);
|
|
32
|
-
return client;
|
|
33
22
|
}
|