bulltrackers-module 1.0.572 → 1.0.574
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.
|
@@ -212,14 +212,14 @@ async function findSubscriptionsForPI(db, logger, piCid, alertTypeId, computatio
|
|
|
212
212
|
return subscriptions;
|
|
213
213
|
}
|
|
214
214
|
} else {
|
|
215
|
-
logger.log('WARN', `[findSubscriptionsForPI] WatchlistMembershipData/${computationDate} not found,
|
|
216
|
-
//
|
|
217
|
-
return
|
|
215
|
+
logger.log('WARN', `[findSubscriptionsForPI] WatchlistMembershipData/${computationDate} not found, returning existing subscriptions (dev overrides only)`);
|
|
216
|
+
// Return subscriptions array which may contain dev overrides
|
|
217
|
+
return subscriptions;
|
|
218
218
|
}
|
|
219
219
|
} catch (error) {
|
|
220
220
|
logger.log('ERROR', `[findSubscriptionsForPI] Error loading WatchlistMembershipData: ${error.message}`);
|
|
221
|
-
//
|
|
222
|
-
return
|
|
221
|
+
// Return subscriptions array which may contain dev overrides
|
|
222
|
+
return subscriptions;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
// Step 2: For each user, read their watchlists from SignedInUsers/{cid}/watchlists
|
|
@@ -298,51 +298,6 @@ async function findSubscriptionsForPI(db, logger, piCid, alertTypeId, computatio
|
|
|
298
298
|
return subscriptions;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
/**
|
|
302
|
-
* Legacy fallback method - scans all watchlists (used if WatchlistMembershipData is not available)
|
|
303
|
-
*/
|
|
304
|
-
async function findSubscriptionsForPILegacy(db, logger, piCid, alertTypeId, configKey) {
|
|
305
|
-
const subscriptions = [];
|
|
306
|
-
|
|
307
|
-
logger.log('INFO', `[findSubscriptionsForPILegacy] Using legacy method to find subscriptions for PI ${piCid}`);
|
|
308
|
-
|
|
309
|
-
// Get all watchlists from legacy path
|
|
310
|
-
const watchlistsCollection = db.collection('watchlists');
|
|
311
|
-
const watchlistsSnapshot = await watchlistsCollection.get();
|
|
312
|
-
|
|
313
|
-
for (const userDoc of watchlistsSnapshot.docs) {
|
|
314
|
-
const userCid = Number(userDoc.id);
|
|
315
|
-
const userListsSnapshot = await userDoc.ref.collection('lists').get();
|
|
316
|
-
|
|
317
|
-
for (const listDoc of userListsSnapshot.docs) {
|
|
318
|
-
const listData = listDoc.data();
|
|
319
|
-
|
|
320
|
-
// Check static watchlists
|
|
321
|
-
if (listData.type === 'static' && listData.items && Array.isArray(listData.items)) {
|
|
322
|
-
for (const item of listData.items) {
|
|
323
|
-
if (Number(item.cid) === Number(piCid)) {
|
|
324
|
-
const isTestProbe = alertTypeId === 'TestSystemProbe';
|
|
325
|
-
const isEnabled = item.alertConfig && item.alertConfig[configKey] === true;
|
|
326
|
-
|
|
327
|
-
if (isTestProbe || isEnabled) {
|
|
328
|
-
subscriptions.push({
|
|
329
|
-
userCid: userCid,
|
|
330
|
-
piCid: piCid,
|
|
331
|
-
piUsername: item.username || `PI-${piCid}`,
|
|
332
|
-
watchlistId: listDoc.id,
|
|
333
|
-
watchlistName: listData.name || 'Unnamed Watchlist',
|
|
334
|
-
alertConfig: item.alertConfig
|
|
335
|
-
});
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return subscriptions;
|
|
345
|
-
}
|
|
346
301
|
|
|
347
302
|
/**
|
|
348
303
|
* Check if alert should trigger based on thresholds
|
|
@@ -162,25 +162,63 @@ async function getUserComputations(req, res, dependencies, config) {
|
|
|
162
162
|
let datesToCheck = [today];
|
|
163
163
|
|
|
164
164
|
if (mode === 'latest') {
|
|
165
|
+
// Use same logic as data-status: search backwards and verify user exists
|
|
166
|
+
// This ensures we find the same date that data-status found
|
|
165
167
|
const firstCompName = computationNames[0];
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
insightsCollection,
|
|
169
|
-
resultsSub,
|
|
170
|
-
compsSub,
|
|
171
|
-
category,
|
|
172
|
-
firstCompName,
|
|
173
|
-
effectiveCid,
|
|
174
|
-
7
|
|
175
|
-
);
|
|
168
|
+
const maxDaysBack = 30; // Match data-status search window
|
|
169
|
+
let foundDate = null;
|
|
176
170
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
171
|
+
for (let daysBack = 0; daysBack < maxDaysBack; daysBack++) {
|
|
172
|
+
const checkDate = new Date();
|
|
173
|
+
checkDate.setDate(checkDate.getDate() - daysBack);
|
|
174
|
+
const dateStr = checkDate.toISOString().split('T')[0];
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
// Check if computation document exists for this date
|
|
178
|
+
const computationRef = db.collection(insightsCollection)
|
|
179
|
+
.doc(dateStr)
|
|
180
|
+
.collection(resultsSub)
|
|
181
|
+
.doc(category)
|
|
182
|
+
.collection(compsSub)
|
|
183
|
+
.doc(firstCompName);
|
|
184
|
+
|
|
185
|
+
const computationDoc = await computationRef.get();
|
|
186
|
+
|
|
187
|
+
if (computationDoc.exists) {
|
|
188
|
+
// Computation exists, verify user is in it (same as data-status)
|
|
189
|
+
const { found } = await checkPiInComputationDate(
|
|
190
|
+
db,
|
|
191
|
+
insightsCollection,
|
|
192
|
+
resultsSub,
|
|
193
|
+
compsSub,
|
|
194
|
+
category,
|
|
195
|
+
firstCompName,
|
|
196
|
+
dateStr,
|
|
197
|
+
String(effectiveCid),
|
|
198
|
+
logger
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
if (found) {
|
|
202
|
+
foundDate = dateStr;
|
|
203
|
+
if (dateStr !== today) {
|
|
204
|
+
logger.log('INFO', `[getUserComputations] Using fallback date ${foundDate} for effective CID ${effectiveCid} (today: ${today})`);
|
|
205
|
+
} else {
|
|
206
|
+
logger.log('INFO', `[getUserComputations] Found computation for effective CID ${effectiveCid} on today's date`);
|
|
207
|
+
}
|
|
208
|
+
break; // Found user, stop searching
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {
|
|
212
|
+
// Continue to next date if error
|
|
213
|
+
logger.log('DEBUG', `[getUserComputations] Error checking date ${dateStr}:`, error.message);
|
|
214
|
+
continue;
|
|
181
215
|
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (foundDate) {
|
|
219
|
+
datesToCheck = [foundDate];
|
|
182
220
|
} else {
|
|
183
|
-
logger.log('WARN', `[getUserComputations] No computation data found for CID ${effectiveCid} in last
|
|
221
|
+
logger.log('WARN', `[getUserComputations] No computation data found for CID ${effectiveCid} in last ${maxDaysBack} days. Frontend will use fallback.`);
|
|
184
222
|
return res.status(200).json({
|
|
185
223
|
status: 'success',
|
|
186
224
|
userCid: String(effectiveCid),
|