@adventurelabs/scout-core 1.0.132 → 1.1.1
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.
|
@@ -3,7 +3,6 @@ import { IVersionsSoftware, VersionsSoftwareInsert } from "../types/db";
|
|
|
3
3
|
import { IWebResponseCompatible } from "../types/requests";
|
|
4
4
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
5
|
export declare function get_versions_software(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IVersionsSoftware[]>>;
|
|
6
|
-
export declare function get_versions_software_with_cache(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IVersionsSoftware[]>>;
|
|
7
6
|
export declare function get_versions_software_by_system(client: SupabaseClient<Database>, system: string): Promise<IWebResponseCompatible<IVersionsSoftware[]>>;
|
|
8
7
|
export declare function create_version_software(client: SupabaseClient<Database>, newVersionSoftware: VersionsSoftwareInsert): Promise<IWebResponseCompatible<IVersionsSoftware | null>>;
|
|
9
8
|
export declare function update_version_software(client: SupabaseClient<Database>, version_id: number, updatedVersionSoftware: Partial<VersionsSoftwareInsert>): Promise<IWebResponseCompatible<IVersionsSoftware | null>>;
|
|
@@ -13,35 +13,6 @@ export async function get_versions_software(client) {
|
|
|
13
13
|
}
|
|
14
14
|
return IWebResponse.success(data).to_compatible();
|
|
15
15
|
}
|
|
16
|
-
export async function get_versions_software_with_cache(client) {
|
|
17
|
-
try {
|
|
18
|
-
// Try to get from cache first
|
|
19
|
-
const cacheResult = await scoutCache.getVersionsSoftware();
|
|
20
|
-
if (cacheResult.data && !cacheResult.isStale) {
|
|
21
|
-
console.log(`[VersionsSoftware] Using cached data (${Math.round(cacheResult.age / 1000)}s old)`);
|
|
22
|
-
return IWebResponse.success(cacheResult.data).to_compatible();
|
|
23
|
-
}
|
|
24
|
-
// Cache miss or stale data - fetch from API
|
|
25
|
-
console.log("[VersionsSoftware] Cache miss or stale, fetching from API");
|
|
26
|
-
const apiResponse = await get_versions_software(client);
|
|
27
|
-
// If API request was successful, cache the result
|
|
28
|
-
if (apiResponse.status === "success" && apiResponse.data) {
|
|
29
|
-
try {
|
|
30
|
-
await scoutCache.setVersionsSoftware(apiResponse.data);
|
|
31
|
-
console.log(`[VersionsSoftware] Cached ${apiResponse.data.length} software versions`);
|
|
32
|
-
}
|
|
33
|
-
catch (cacheError) {
|
|
34
|
-
console.warn("[VersionsSoftware] Failed to cache data:", cacheError);
|
|
35
|
-
// Continue anyway, we still have the API data
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return apiResponse;
|
|
39
|
-
}
|
|
40
|
-
catch (cacheError) {
|
|
41
|
-
console.warn("[VersionsSoftware] Cache error, falling back to API:", cacheError);
|
|
42
|
-
return get_versions_software(client);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
16
|
export async function get_versions_software_by_system(client, system) {
|
|
46
17
|
const { data, error } = await client
|
|
47
18
|
.from("versions_software")
|
|
@@ -28,12 +28,14 @@ export function useScoutRealtimeDevices(scoutSupabase) {
|
|
|
28
28
|
case "UPDATE":
|
|
29
29
|
operation = EnumRealtimeOperation.UPDATE;
|
|
30
30
|
if (data.record) {
|
|
31
|
+
console.log("[Devices] Device updated:", data.record);
|
|
31
32
|
dispatch(updateDevice(data.record));
|
|
32
33
|
}
|
|
33
34
|
break;
|
|
34
35
|
case "DELETE":
|
|
35
36
|
operation = EnumRealtimeOperation.DELETE;
|
|
36
37
|
if (data.old_record) {
|
|
38
|
+
console.log("[Devices] Device deleted:", data.old_record);
|
|
37
39
|
dispatch(deleteDevice(data.old_record));
|
|
38
40
|
}
|
|
39
41
|
break;
|
|
@@ -26,12 +26,14 @@ export function useScoutRealtimeVersionsSoftware(scoutSupabase) {
|
|
|
26
26
|
case "UPDATE":
|
|
27
27
|
operation = EnumRealtimeOperation.UPDATE;
|
|
28
28
|
if (data.record) {
|
|
29
|
+
console.log("[VersionsSoftware] Version updated:", data.record);
|
|
29
30
|
dispatch(upsertVersionSoftware(data.record));
|
|
30
31
|
}
|
|
31
32
|
break;
|
|
32
33
|
case "DELETE":
|
|
33
34
|
operation = EnumRealtimeOperation.DELETE;
|
|
34
35
|
if (data.old_record) {
|
|
36
|
+
console.log("[VersionsSoftware] Version deleted:", data.old_record);
|
|
35
37
|
dispatch(deleteVersionSoftwareById(data.old_record.id));
|
|
36
38
|
}
|
|
37
39
|
break;
|
|
@@ -4,7 +4,7 @@ import { useStore } from "react-redux";
|
|
|
4
4
|
import { EnumScoutStateStatus, setHerdModules, setStatus, setHerdModulesLoadingState, setHerdModulesLoadedInMs, setHerdModulesApiServerProcessingDuration, setHerdModulesApiTotalRequestDuration, setUserApiDuration, setDataProcessingDuration, setCacheLoadDuration, setUser, setDataSource, setDataSourceInfo, setVersionsSoftware, } from "../store/scout";
|
|
5
5
|
import { EnumHerdModulesLoadingState } from "../types/herd_module";
|
|
6
6
|
import { server_load_herd_modules } from "../helpers/herds";
|
|
7
|
-
import {
|
|
7
|
+
import { get_versions_software } from "../helpers/versions_software";
|
|
8
8
|
import { scoutCache } from "../helpers/cache";
|
|
9
9
|
import { EnumDataSource } from "../types/data_source";
|
|
10
10
|
import { createBrowserClient } from "@supabase/ssr";
|
|
@@ -110,7 +110,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
110
110
|
console.log(`[useScoutRefresh] Updating store with cached herd modules`);
|
|
111
111
|
dispatch(setHerdModules(cachedHerdModules));
|
|
112
112
|
dispatch(setHerdModulesLoadingState(EnumHerdModulesLoadingState.SUCCESSFULLY_LOADED));
|
|
113
|
-
// Load cached software versions if available
|
|
113
|
+
// Load cached software versions immediately if available
|
|
114
114
|
if (versionsCacheResult.data && !versionsCacheResult.isStale) {
|
|
115
115
|
console.log(`[useScoutRefresh] Loaded ${versionsCacheResult.data.length} software versions from cache`);
|
|
116
116
|
dispatch(setVersionsSoftware(versionsCacheResult.data));
|
|
@@ -120,6 +120,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
120
120
|
// Background fetch fresh data without blocking
|
|
121
121
|
(async () => {
|
|
122
122
|
try {
|
|
123
|
+
console.log("[useScoutRefresh] Starting background parallel API calls: herd modules, user, software versions");
|
|
123
124
|
const backgroundStartTime = Date.now();
|
|
124
125
|
const [backgroundHerdModulesResult, backgroundUserResult, backgroundVersionsResult,] = await Promise.all([
|
|
125
126
|
(async () => {
|
|
@@ -147,46 +148,43 @@ export function useScoutRefresh(options = {}) {
|
|
|
147
148
|
})(),
|
|
148
149
|
(async () => {
|
|
149
150
|
const start = Date.now();
|
|
150
|
-
const result = await
|
|
151
|
+
const result = await get_versions_software(supabase);
|
|
151
152
|
const duration = Date.now() - start;
|
|
152
153
|
return { ...result, duration };
|
|
153
154
|
})(),
|
|
154
155
|
]);
|
|
155
156
|
const backgroundDuration = Date.now() - backgroundStartTime;
|
|
157
|
+
console.log(`[useScoutRefresh] Background parallel API calls completed in ${backgroundDuration}ms (herd modules, user, software versions)`);
|
|
156
158
|
// Validate background responses
|
|
157
159
|
if (backgroundHerdModulesResult.status === "success" &&
|
|
158
160
|
backgroundHerdModulesResult.data &&
|
|
159
161
|
Array.isArray(backgroundHerdModulesResult.data) &&
|
|
160
162
|
backgroundUserResult &&
|
|
161
163
|
backgroundUserResult.data) {
|
|
162
|
-
// Update cache with fresh data
|
|
164
|
+
// Update cache with fresh herd modules data
|
|
163
165
|
try {
|
|
164
|
-
await
|
|
165
|
-
scoutCache.setHerdModules(backgroundHerdModulesResult.data, cacheTtlMs),
|
|
166
|
-
backgroundVersionsResult &&
|
|
167
|
-
backgroundVersionsResult.status === "success" &&
|
|
168
|
-
backgroundVersionsResult.data
|
|
169
|
-
? scoutCache.setVersionsSoftware(backgroundVersionsResult.data, cacheTtlMs)
|
|
170
|
-
: Promise.resolve(),
|
|
171
|
-
]);
|
|
166
|
+
await scoutCache.setHerdModules(backgroundHerdModulesResult.data, cacheTtlMs);
|
|
172
167
|
}
|
|
173
168
|
catch (cacheError) {
|
|
174
|
-
console.warn("[useScoutRefresh] Background cache save failed:", cacheError);
|
|
169
|
+
console.warn("[useScoutRefresh] Background herd modules cache save failed:", cacheError);
|
|
175
170
|
await handleIndexedDbError(cacheError, "background cache save", async () => {
|
|
176
|
-
const promises = [];
|
|
177
171
|
if (backgroundHerdModulesResult.data) {
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
if (backgroundVersionsResult &&
|
|
181
|
-
backgroundVersionsResult.status === "success" &&
|
|
182
|
-
backgroundVersionsResult.data) {
|
|
183
|
-
promises.push(scoutCache.setVersionsSoftware(backgroundVersionsResult.data, cacheTtlMs));
|
|
184
|
-
}
|
|
185
|
-
if (promises.length > 0) {
|
|
186
|
-
await Promise.all(promises);
|
|
172
|
+
await scoutCache.setHerdModules(backgroundHerdModulesResult.data, cacheTtlMs);
|
|
187
173
|
}
|
|
188
174
|
});
|
|
189
175
|
}
|
|
176
|
+
// Update cache with fresh software versions separately
|
|
177
|
+
if (backgroundVersionsResult &&
|
|
178
|
+
backgroundVersionsResult.status === "success" &&
|
|
179
|
+
backgroundVersionsResult.data) {
|
|
180
|
+
try {
|
|
181
|
+
await scoutCache.setVersionsSoftware(backgroundVersionsResult.data, cacheTtlMs);
|
|
182
|
+
console.log(`[useScoutRefresh] Background cached ${backgroundVersionsResult.data.length} software versions`);
|
|
183
|
+
}
|
|
184
|
+
catch (versionsCacheError) {
|
|
185
|
+
console.warn("[useScoutRefresh] Background software versions cache save failed:", versionsCacheError);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
190
188
|
// Update store with fresh data from background request
|
|
191
189
|
console.log(`[useScoutRefresh] Updating store with background herd modules`);
|
|
192
190
|
dispatch(setHerdModules(backgroundHerdModulesResult.data));
|
|
@@ -232,7 +230,8 @@ export function useScoutRefresh(options = {}) {
|
|
|
232
230
|
// Continue with API call
|
|
233
231
|
}
|
|
234
232
|
}
|
|
235
|
-
// Step 2: Load fresh data from API
|
|
233
|
+
// Step 2: Load fresh data from API (herd modules, user, and software versions in parallel)
|
|
234
|
+
console.log("[useScoutRefresh] Starting parallel API calls: herd modules, user, software versions");
|
|
236
235
|
const parallelStartTime = Date.now();
|
|
237
236
|
const [herdModulesResult, userResult, versionsResult] = await Promise.all([
|
|
238
237
|
(async () => {
|
|
@@ -254,7 +253,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
254
253
|
})(),
|
|
255
254
|
(async () => {
|
|
256
255
|
const start = Date.now();
|
|
257
|
-
const result = await
|
|
256
|
+
const result = await get_versions_software(supabase);
|
|
258
257
|
const duration = Date.now() - start;
|
|
259
258
|
return {
|
|
260
259
|
result,
|
|
@@ -264,7 +263,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
264
263
|
})(),
|
|
265
264
|
]);
|
|
266
265
|
const parallelDuration = Date.now() - parallelStartTime;
|
|
267
|
-
console.log(`[useScoutRefresh] Parallel API
|
|
266
|
+
console.log(`[useScoutRefresh] Parallel API calls completed in ${parallelDuration}ms (herd modules, user, software versions)`);
|
|
268
267
|
// Extract results and timing
|
|
269
268
|
const herdModulesResponse = herdModulesResult.result;
|
|
270
269
|
const res_new_user = userResult.result;
|
|
@@ -305,30 +304,26 @@ export function useScoutRefresh(options = {}) {
|
|
|
305
304
|
// Step 3: Update cache with fresh data
|
|
306
305
|
const cacheSaveStartTime = Date.now();
|
|
307
306
|
try {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
];
|
|
311
|
-
// Cache software versions if available
|
|
307
|
+
await scoutCache.setHerdModules(compatible_new_herd_modules, cacheTtlMs);
|
|
308
|
+
// Cache software versions separately
|
|
312
309
|
if (versionsResult.result.status === "success" &&
|
|
313
310
|
versionsResult.result.data) {
|
|
314
|
-
|
|
311
|
+
try {
|
|
312
|
+
await scoutCache.setVersionsSoftware(versionsResult.result.data, cacheTtlMs);
|
|
313
|
+
console.log(`[useScoutRefresh] Cached ${versionsResult.result.data.length} software versions`);
|
|
314
|
+
}
|
|
315
|
+
catch (versionsCacheError) {
|
|
316
|
+
console.warn("[useScoutRefresh] Failed to cache software versions:", versionsCacheError);
|
|
317
|
+
}
|
|
315
318
|
}
|
|
316
|
-
await Promise.all(cachePromises);
|
|
317
319
|
const cacheSaveDuration = Date.now() - cacheSaveStartTime;
|
|
318
320
|
timingRefs.current.cacheSaveDuration = cacheSaveDuration;
|
|
319
321
|
console.log(`[useScoutRefresh] Cache updated in ${cacheSaveDuration}ms with TTL: ${Math.round(cacheTtlMs / 1000)}s`);
|
|
320
322
|
}
|
|
321
323
|
catch (cacheError) {
|
|
322
|
-
console.warn("[useScoutRefresh]
|
|
324
|
+
console.warn("[useScoutRefresh] Herd modules cache save failed:", cacheError);
|
|
323
325
|
await handleIndexedDbError(cacheError, "cache save", async () => {
|
|
324
|
-
|
|
325
|
-
scoutCache.setHerdModules(compatible_new_herd_modules, cacheTtlMs),
|
|
326
|
-
];
|
|
327
|
-
if (versionsResult.result.status === "success" &&
|
|
328
|
-
versionsResult.result.data) {
|
|
329
|
-
retryPromises.push(scoutCache.setVersionsSoftware(versionsResult.result.data, cacheTtlMs));
|
|
330
|
-
}
|
|
331
|
-
await Promise.all(retryPromises);
|
|
326
|
+
await scoutCache.setHerdModules(compatible_new_herd_modules, cacheTtlMs);
|
|
332
327
|
});
|
|
333
328
|
}
|
|
334
329
|
// Step 4: Conditionally update store with fresh data, skip timestamp-only changes
|