@adventurelabs/scout-core 1.0.40 → 1.0.42
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/api_keys/actions.js +11 -5
- package/dist/helpers/tags.js +30 -46
- package/dist/providers/ScoutRefreshProvider.d.ts +15 -22
- package/dist/supabase/server.d.ts +15 -22
- package/dist/types/herd_module.js +6 -2
- package/dist/types/supabase.d.ts +15 -22
- package/package.json +1 -1
package/dist/api_keys/actions.js
CHANGED
|
@@ -18,18 +18,23 @@ export async function server_list_api_keys(device_id) {
|
|
|
18
18
|
return data_to_return;
|
|
19
19
|
}
|
|
20
20
|
export async function server_list_api_keys_batch(device_ids) {
|
|
21
|
-
|
|
21
|
+
const startTime = Date.now();
|
|
22
|
+
console.log(`[API Keys Batch] Starting batch load for ${device_ids.length} devices at ${new Date().toISOString()}`);
|
|
22
23
|
const supabase = await newServerClient();
|
|
24
|
+
console.log(`[API Keys Batch] Making RPC call to load_api_keys_batch...`);
|
|
23
25
|
const { data, error } = await supabase.rpc("load_api_keys_batch", {
|
|
24
26
|
device_ids: device_ids,
|
|
25
27
|
});
|
|
28
|
+
const duration = Date.now() - startTime;
|
|
26
29
|
if (error) {
|
|
27
|
-
console.error(
|
|
30
|
+
console.error(`[API Keys Batch] ERROR after ${duration}ms:`, error.message);
|
|
28
31
|
return {};
|
|
29
32
|
}
|
|
30
|
-
if (!data)
|
|
33
|
+
if (!data) {
|
|
34
|
+
console.log(`[API Keys Batch] No data returned after ${duration}ms`);
|
|
31
35
|
return {};
|
|
32
|
-
|
|
36
|
+
}
|
|
37
|
+
console.log(`[API Keys Batch] RPC completed in ${duration}ms, received ${data.length} API key records`);
|
|
33
38
|
const result = {};
|
|
34
39
|
// Group API keys by device_id
|
|
35
40
|
data.forEach((item) => {
|
|
@@ -42,6 +47,7 @@ export async function server_list_api_keys_batch(device_ids) {
|
|
|
42
47
|
key: item.api_key_key,
|
|
43
48
|
});
|
|
44
49
|
});
|
|
45
|
-
|
|
50
|
+
const totalDuration = Date.now() - startTime;
|
|
51
|
+
console.log(`[API Keys Batch] COMPLETED in ${totalDuration}ms - returning API keys for ${Object.keys(result).length} devices`);
|
|
46
52
|
return result;
|
|
47
53
|
}
|
package/dist/helpers/tags.js
CHANGED
|
@@ -147,24 +147,29 @@ export async function server_get_events_and_tags_for_device(device_id, limit = 3
|
|
|
147
147
|
return IWebResponse.success(eventsWithSignedUrls).to_compatible();
|
|
148
148
|
}
|
|
149
149
|
export async function server_get_events_and_tags_for_devices_batch(device_ids, limit = 1) {
|
|
150
|
-
|
|
150
|
+
const startTime = Date.now();
|
|
151
|
+
console.log(`[Events Batch] Starting batch load for ${device_ids.length} devices (limit: ${limit}) at ${new Date().toISOString()}`);
|
|
151
152
|
const supabase = await newServerClient();
|
|
153
|
+
console.log(`[Events Batch] Making RPC call to get_events_and_tags_for_devices_batch...`);
|
|
152
154
|
// Use single RPC call for all devices
|
|
153
155
|
const { data, error } = await supabase.rpc("get_events_and_tags_for_devices_batch", {
|
|
154
156
|
device_ids: device_ids,
|
|
155
157
|
limit_per_device: limit,
|
|
156
158
|
});
|
|
159
|
+
const duration = Date.now() - startTime;
|
|
157
160
|
if (error) {
|
|
158
|
-
console.error(
|
|
161
|
+
console.error(`[Events Batch] ERROR after ${duration}ms:`, error.message);
|
|
159
162
|
return {
|
|
160
163
|
status: EnumWebResponse.ERROR,
|
|
161
164
|
msg: error.message,
|
|
162
165
|
data: {},
|
|
163
166
|
};
|
|
164
167
|
}
|
|
165
|
-
if (!data)
|
|
168
|
+
if (!data) {
|
|
169
|
+
console.log(`[Events Batch] No data returned after ${duration}ms`);
|
|
166
170
|
return IWebResponse.success({}).to_compatible();
|
|
167
|
-
|
|
171
|
+
}
|
|
172
|
+
console.log(`[Events Batch] RPC completed in ${duration}ms, received ${data.length} event records`);
|
|
168
173
|
// Group events by device_id
|
|
169
174
|
const eventsByDevice = {};
|
|
170
175
|
data.forEach((row) => {
|
|
@@ -172,47 +177,25 @@ export async function server_get_events_and_tags_for_devices_batch(device_ids, l
|
|
|
172
177
|
if (!eventsByDevice[device_id]) {
|
|
173
178
|
eventsByDevice[device_id] = [];
|
|
174
179
|
}
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
timestamp_observation: row.event_timestamp_observation,
|
|
195
|
-
is_public: row.event_is_public,
|
|
196
|
-
earthranger_url: row.event_earthranger_url,
|
|
197
|
-
tags: [],
|
|
198
|
-
};
|
|
199
|
-
eventsByDevice[device_id].push(event);
|
|
200
|
-
}
|
|
201
|
-
// Add tag if it exists
|
|
202
|
-
if (row.tag_id) {
|
|
203
|
-
event.tags.push({
|
|
204
|
-
id: row.tag_id,
|
|
205
|
-
x: row.tag_x || 0,
|
|
206
|
-
y: row.tag_y || 0,
|
|
207
|
-
width: row.tag_width || 0,
|
|
208
|
-
height: row.tag_height || 0,
|
|
209
|
-
class_name: row.tag_class_name || "",
|
|
210
|
-
conf: row.tag_conf || 0,
|
|
211
|
-
observation_type: row.tag_observation_type || "manual",
|
|
212
|
-
event_id: row.event_id,
|
|
213
|
-
inserted_at: row.tag_inserted_at || row.event_inserted_at,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
180
|
+
// Create event object from the new structure
|
|
181
|
+
const event = {
|
|
182
|
+
id: row.event_id,
|
|
183
|
+
inserted_at: row.inserted_at,
|
|
184
|
+
message: row.message,
|
|
185
|
+
media_url: row.media_url,
|
|
186
|
+
file_path: row.file_path,
|
|
187
|
+
latitude: row.latitude,
|
|
188
|
+
longitude: row.longitude,
|
|
189
|
+
altitude: row.altitude,
|
|
190
|
+
heading: row.heading,
|
|
191
|
+
media_type: row.media_type,
|
|
192
|
+
device_id: device_id,
|
|
193
|
+
timestamp_observation: row.timestamp_observation,
|
|
194
|
+
is_public: row.is_public,
|
|
195
|
+
earthranger_url: row.earthranger_url,
|
|
196
|
+
tags: Array.isArray(row.tags) ? row.tags : [],
|
|
197
|
+
};
|
|
198
|
+
eventsByDevice[device_id].push(event);
|
|
216
199
|
});
|
|
217
200
|
// Add signed URLs to all events
|
|
218
201
|
const result = {};
|
|
@@ -221,7 +204,8 @@ export async function server_get_events_and_tags_for_devices_batch(device_ids, l
|
|
|
221
204
|
const eventsWithSignedUrls = await addSignedUrlsToEvents(events, supabase);
|
|
222
205
|
result[parseInt(device_id)] = eventsWithSignedUrls;
|
|
223
206
|
}
|
|
224
|
-
|
|
207
|
+
const totalDuration = Date.now() - startTime;
|
|
208
|
+
console.log(`[Events Batch] COMPLETED in ${totalDuration}ms - returning events for ${Object.keys(result).length} devices`);
|
|
225
209
|
return IWebResponse.success(result).to_compatible();
|
|
226
210
|
}
|
|
227
211
|
export async function get_event_and_tags_by_event_id(event_id) {
|
|
@@ -760,29 +760,22 @@ export declare function useSupabase(): SupabaseClient<Database, "public", {
|
|
|
760
760
|
limit_per_device: number;
|
|
761
761
|
};
|
|
762
762
|
Returns: {
|
|
763
|
-
device_id: number;
|
|
764
763
|
event_id: number;
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
tag_width: number | null;
|
|
781
|
-
tag_height: number | null;
|
|
782
|
-
tag_class_name: string | null;
|
|
783
|
-
tag_conf: number | null;
|
|
784
|
-
tag_observation_type: string | null;
|
|
785
|
-
tag_inserted_at: string | null;
|
|
764
|
+
inserted_at: string;
|
|
765
|
+
message: string | null;
|
|
766
|
+
media_url: string | null;
|
|
767
|
+
file_path: string | null;
|
|
768
|
+
latitude: number | null;
|
|
769
|
+
longitude: number | null;
|
|
770
|
+
earthranger_url: string | null;
|
|
771
|
+
altitude: number;
|
|
772
|
+
heading: number;
|
|
773
|
+
media_type: string;
|
|
774
|
+
device_id: number;
|
|
775
|
+
timestamp_observation: string;
|
|
776
|
+
is_public: boolean;
|
|
777
|
+
tags: import("../types/supabase").Json;
|
|
778
|
+
herd_id: number | null;
|
|
786
779
|
}[];
|
|
787
780
|
};
|
|
788
781
|
};
|
|
@@ -751,29 +751,22 @@ export declare function newServerClient(): Promise<import("@supabase/supabase-js
|
|
|
751
751
|
limit_per_device: number;
|
|
752
752
|
};
|
|
753
753
|
Returns: {
|
|
754
|
-
device_id: number;
|
|
755
754
|
event_id: number;
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
tag_width: number | null;
|
|
772
|
-
tag_height: number | null;
|
|
773
|
-
tag_class_name: string | null;
|
|
774
|
-
tag_conf: number | null;
|
|
775
|
-
tag_observation_type: string | null;
|
|
776
|
-
tag_inserted_at: string | null;
|
|
755
|
+
inserted_at: string;
|
|
756
|
+
message: string | null;
|
|
757
|
+
media_url: string | null;
|
|
758
|
+
file_path: string | null;
|
|
759
|
+
latitude: number | null;
|
|
760
|
+
longitude: number | null;
|
|
761
|
+
earthranger_url: string | null;
|
|
762
|
+
altitude: number;
|
|
763
|
+
heading: number;
|
|
764
|
+
media_type: string;
|
|
765
|
+
device_id: number;
|
|
766
|
+
timestamp_observation: string;
|
|
767
|
+
is_public: boolean;
|
|
768
|
+
tags: import("../types/supabase").Json;
|
|
769
|
+
herd_id: number | null;
|
|
777
770
|
}[];
|
|
778
771
|
};
|
|
779
772
|
};
|
|
@@ -59,14 +59,18 @@ export class HerdModule {
|
|
|
59
59
|
// get api keys and events for all devices in batch
|
|
60
60
|
let recent_events_batch = {};
|
|
61
61
|
if (new_devices.length > 0) {
|
|
62
|
+
const batchStartTime = Date.now();
|
|
62
63
|
try {
|
|
63
64
|
const device_ids = new_devices.map((device) => device.id ?? 0);
|
|
64
|
-
console.log(`[HerdModule]
|
|
65
|
+
console.log(`[HerdModule] Starting parallel batch load for ${device_ids.length} devices at ${new Date().toISOString()}:`, device_ids);
|
|
65
66
|
// Load API keys and events in parallel
|
|
67
|
+
console.log(`[HerdModule] Initiating Promise.all for API keys and events...`);
|
|
66
68
|
const [api_keys_batch, events_response] = await Promise.all([
|
|
67
69
|
server_list_api_keys_batch(device_ids),
|
|
68
70
|
server_get_events_and_tags_for_devices_batch(device_ids, 1),
|
|
69
71
|
]);
|
|
72
|
+
const batchDuration = Date.now() - batchStartTime;
|
|
73
|
+
console.log(`[HerdModule] Parallel batch load completed in ${batchDuration}ms`);
|
|
70
74
|
// Assign API keys to devices
|
|
71
75
|
for (let i = 0; i < new_devices.length; i++) {
|
|
72
76
|
const device_id = new_devices[i].id ?? 0;
|
|
@@ -81,7 +85,7 @@ export class HerdModule {
|
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
catch (error) {
|
|
84
|
-
console.
|
|
88
|
+
console.error(`[HerdModule] CRITICAL ERROR in batch load after ${Date.now() - batchStartTime}ms:`, error);
|
|
85
89
|
// Continue without API keys and events
|
|
86
90
|
}
|
|
87
91
|
}
|
package/dist/types/supabase.d.ts
CHANGED
|
@@ -818,29 +818,22 @@ export type Database = {
|
|
|
818
818
|
limit_per_device: number;
|
|
819
819
|
};
|
|
820
820
|
Returns: {
|
|
821
|
-
device_id: number;
|
|
822
821
|
event_id: number;
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
tag_width: number | null;
|
|
839
|
-
tag_height: number | null;
|
|
840
|
-
tag_class_name: string | null;
|
|
841
|
-
tag_conf: number | null;
|
|
842
|
-
tag_observation_type: string | null;
|
|
843
|
-
tag_inserted_at: string | null;
|
|
822
|
+
inserted_at: string;
|
|
823
|
+
message: string | null;
|
|
824
|
+
media_url: string | null;
|
|
825
|
+
file_path: string | null;
|
|
826
|
+
latitude: number | null;
|
|
827
|
+
longitude: number | null;
|
|
828
|
+
earthranger_url: string | null;
|
|
829
|
+
altitude: number;
|
|
830
|
+
heading: number;
|
|
831
|
+
media_type: string;
|
|
832
|
+
device_id: number;
|
|
833
|
+
timestamp_observation: string;
|
|
834
|
+
is_public: boolean;
|
|
835
|
+
tags: Json;
|
|
836
|
+
herd_id: number | null;
|
|
844
837
|
}[];
|
|
845
838
|
};
|
|
846
839
|
};
|