@adventurelabs/scout-core 1.0.64 → 1.0.66
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
CHANGED
|
@@ -3,7 +3,12 @@ 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()}`);
|
|
6
8
|
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`);
|
|
7
12
|
if (!herds) {
|
|
8
13
|
return {
|
|
9
14
|
status: EnumWebResponse.ERROR,
|
|
@@ -65,29 +70,57 @@ export async function createHerd(newHerd) {
|
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
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()}`);
|
|
68
75
|
const startTime = Date.now();
|
|
69
|
-
//
|
|
76
|
+
// Measure Supabase client creation
|
|
77
|
+
const supabaseStartTime = Date.now();
|
|
70
78
|
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();
|
|
71
83
|
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`);
|
|
72
86
|
if (new_herds.status != EnumWebResponse.SUCCESS || !new_herds.data) {
|
|
87
|
+
const errorTime = Date.now();
|
|
73
88
|
return {
|
|
74
89
|
status: EnumWebResponse.ERROR,
|
|
75
90
|
msg: "No herds found",
|
|
76
91
|
data: null,
|
|
77
|
-
time_finished:
|
|
78
|
-
time_sent:
|
|
79
|
-
server_processing_time_ms:
|
|
92
|
+
time_finished: errorTime,
|
|
93
|
+
time_sent: errorTime,
|
|
94
|
+
server_processing_time_ms: errorTime - startTime,
|
|
80
95
|
};
|
|
81
96
|
}
|
|
82
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();
|
|
83
100
|
let new_herd_modules = [];
|
|
84
101
|
const herdModulePromises = new_herds.data.map((herd) => HerdModule.from_herd(herd, client_supabase));
|
|
85
102
|
new_herd_modules = await Promise.all(herdModulePromises);
|
|
86
|
-
|
|
103
|
+
const herdModuleTime = Date.now() - herdModuleStartTime;
|
|
104
|
+
console.log(`[server_load_herd_modules] Herd module creation took: ${herdModuleTime}ms`);
|
|
105
|
+
// Measure serialization
|
|
106
|
+
const serializationStartTime = Date.now();
|
|
87
107
|
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`);
|
|
88
110
|
const endTime = Date.now();
|
|
89
111
|
const totalLoadTime = endTime - startTime;
|
|
112
|
+
// Calculate detailed timing breakdown
|
|
113
|
+
const timeToClient = endTime - requestReceivedTime;
|
|
114
|
+
const processingTime = endTime - startTime;
|
|
90
115
|
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`);
|
|
91
124
|
// Record the time when we're about to send the response
|
|
92
125
|
const timeSent = Date.now();
|
|
93
126
|
return {
|
package/dist/helpers/users.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IUser, IUserAndRole, IUserRolePerHerd, Role } from "../types/db";
|
|
2
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
3
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
3
4
|
export declare function server_get_user_roles(herd_id: number): Promise<IWebResponseCompatible<IUserRolePerHerd[]>>;
|
|
4
5
|
export declare function server_get_user(): Promise<IWebResponseCompatible<IUser | null>>;
|
|
5
|
-
export declare function server_get_users_with_herd_access(herd_id: number): Promise<IWebResponseCompatible<IUserAndRole[]
|
|
6
|
+
export declare function server_get_users_with_herd_access(herd_id: number, supabaseClient?: SupabaseClient): Promise<IWebResponseCompatible<IUserAndRole[]>>;
|
|
6
7
|
export declare function server_upsert_user_with_role(herd_id: number, username: string, role: Role): Promise<IWebResponseCompatible<IUserAndRole | null>>;
|
package/dist/helpers/users.js
CHANGED
|
@@ -25,16 +25,33 @@ export async function server_get_user() {
|
|
|
25
25
|
const new_user = data.user;
|
|
26
26
|
return IWebResponse.success(new_user).to_compatible();
|
|
27
27
|
}
|
|
28
|
-
export async function server_get_users_with_herd_access(herd_id) {
|
|
29
|
-
const supabase = await newServerClient();
|
|
28
|
+
export async function server_get_users_with_herd_access(herd_id, supabaseClient) {
|
|
29
|
+
const supabase = supabaseClient || (await newServerClient());
|
|
30
30
|
const { data, error } = await supabase
|
|
31
31
|
.from("users_roles_per_herd")
|
|
32
|
-
.select(
|
|
32
|
+
.select(`
|
|
33
|
+
role,
|
|
34
|
+
users (
|
|
35
|
+
id,
|
|
36
|
+
username
|
|
37
|
+
)
|
|
38
|
+
`)
|
|
33
39
|
.eq("herd_id", herd_id);
|
|
34
40
|
if (error) {
|
|
35
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
status: EnumWebResponse.ERROR,
|
|
43
|
+
msg: error.message,
|
|
44
|
+
data: null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Transform the data to match IUserAndRole interface
|
|
49
|
+
const transformedData = data.map((item) => ({
|
|
50
|
+
user: item.users,
|
|
51
|
+
role: item.role,
|
|
52
|
+
}));
|
|
53
|
+
return IWebResponse.success(transformedData).to_compatible();
|
|
36
54
|
}
|
|
37
|
-
return IWebResponse.success(data).to_compatible();
|
|
38
55
|
}
|
|
39
56
|
export async function server_upsert_user_with_role(herd_id, username, role) {
|
|
40
57
|
const supabase = await newServerClient();
|
|
@@ -60,6 +60,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
60
60
|
(async () => {
|
|
61
61
|
const start = Date.now();
|
|
62
62
|
console.log(`[useScoutRefresh] Starting herd modules request at ${new Date(start).toISOString()}`);
|
|
63
|
+
// High priority request with optimization
|
|
63
64
|
const result = await server_load_herd_modules();
|
|
64
65
|
const duration = Date.now() - start;
|
|
65
66
|
console.log(`[useScoutRefresh] Herd modules request completed in ${duration}ms`);
|
|
@@ -68,6 +69,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
68
69
|
(async () => {
|
|
69
70
|
const start = Date.now();
|
|
70
71
|
console.log(`[useScoutRefresh] Starting user request at ${new Date(start).toISOString()}`);
|
|
72
|
+
// High priority request with optimization
|
|
71
73
|
const result = await server_get_user();
|
|
72
74
|
const duration = Date.now() - start;
|
|
73
75
|
console.log(`[useScoutRefresh] User request completed in ${duration}ms`);
|
package/dist/supabase/server.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
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();
|
|
4
7
|
const cookieStore = await cookies();
|
|
5
|
-
|
|
8
|
+
const cookieTime = Date.now() - cookieStartTime;
|
|
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, {
|
|
6
12
|
cookies: {
|
|
7
13
|
getAll() {
|
|
8
14
|
return cookieStore.getAll();
|
|
@@ -19,4 +25,9 @@ export async function newServerClient() {
|
|
|
19
25
|
},
|
|
20
26
|
},
|
|
21
27
|
});
|
|
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;
|
|
22
33
|
}
|
|
@@ -100,7 +100,7 @@ export class HerdModule {
|
|
|
100
100
|
console.warn(`[HerdModule] Failed to get zones and actions:`, error);
|
|
101
101
|
return { status: EnumWebResponse.ERROR, data: null };
|
|
102
102
|
}),
|
|
103
|
-
server_get_users_with_herd_access(herd.id).catch((error) => {
|
|
103
|
+
server_get_users_with_herd_access(herd.id, client).catch((error) => {
|
|
104
104
|
console.warn(`[HerdModule] Failed to get user roles:`, error);
|
|
105
105
|
return { status: EnumWebResponse.ERROR, data: null };
|
|
106
106
|
}),
|