bulltrackers-module 1.0.579 → 1.0.580

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.
@@ -209,56 +209,99 @@ async function getUserComputations(req, res, dependencies, config) {
209
209
 
210
210
  const isDevOverrideActive = devOverride && devOverride.enabled && devOverride.fakeCopiedPIs.length > 0;
211
211
 
212
+ // Check if any of the requested computations are meta computations
213
+ const firstCompName = computationNames[0];
214
+ const firstCompMetadata = computationMetadata[firstCompName];
215
+ const isMetaComputation = firstCompMetadata && firstCompMetadata.type === 'meta';
216
+
212
217
  let datesToCheck = [today];
213
218
 
214
219
  if (mode === 'latest') {
215
- // Use same logic as data-status: search backwards and verify user exists
216
- // This ensures we find the same date that data-status found
217
- const firstCompName = computationNames[0];
218
- const maxDaysBack = 30; // Match data-status search window
219
220
  let foundDate = null;
220
221
 
221
- for (let daysBack = 0; daysBack < maxDaysBack; daysBack++) {
222
- const checkDate = new Date();
223
- checkDate.setDate(checkDate.getDate() - daysBack);
224
- const dateStr = checkDate.toISOString().split('T')[0];
222
+ if (isMetaComputation) {
223
+ // For meta computations: check today first, then look back 7 days
224
+ const maxDaysBack = 7;
225
225
 
226
- try {
227
- // Check if page/computation document exists for this user and date
228
- // For computations using pages subcollection, checkPiInComputationDate handles it
229
- // For other computations, check the main document first
230
- const { found } = await checkPiInComputationDate(
231
- db,
232
- insightsCollection,
233
- resultsSub,
234
- compsSub,
235
- category,
236
- firstCompName,
237
- dateStr,
238
- String(effectiveCid),
239
- logger
240
- );
226
+ for (let daysBack = 0; daysBack < maxDaysBack; daysBack++) {
227
+ const checkDate = new Date();
228
+ checkDate.setDate(checkDate.getDate() - daysBack);
229
+ const dateStr = checkDate.toISOString().split('T')[0];
230
+
231
+ try {
232
+ // For meta computations, just check if the document exists
233
+ const computationRef = db.collection(insightsCollection)
234
+ .doc(dateStr)
235
+ .collection(resultsSub)
236
+ .doc(category)
237
+ .collection(compsSub)
238
+ .doc(firstCompName);
239
+
240
+ const computationDoc = await computationRef.get();
241
+
242
+ if (computationDoc.exists) {
243
+ foundDate = dateStr;
244
+ if (dateStr !== today) {
245
+ logger.log('INFO', `[getUserComputations] Meta computation ${firstCompName} found on fallback date ${foundDate} (today: ${today})`);
246
+ } else {
247
+ logger.log('INFO', `[getUserComputations] Meta computation ${firstCompName} found on today's date`);
248
+ }
249
+ break; // Found document, stop searching
250
+ }
251
+ } catch (error) {
252
+ // Continue to next date if error
253
+ logger.log('DEBUG', `[getUserComputations] Error checking date ${dateStr} for meta computation:`, error.message);
254
+ continue;
255
+ }
256
+ }
257
+ } else {
258
+ // For user-specific computations: use same logic as data-status
259
+ // Search backwards and verify user exists
260
+ const maxDaysBack = 30; // Match data-status search window
261
+
262
+ for (let daysBack = 0; daysBack < maxDaysBack; daysBack++) {
263
+ const checkDate = new Date();
264
+ checkDate.setDate(checkDate.getDate() - daysBack);
265
+ const dateStr = checkDate.toISOString().split('T')[0];
241
266
 
242
- if (found) {
243
- foundDate = dateStr;
244
- if (dateStr !== today) {
245
- logger.log('INFO', `[getUserComputations] Using fallback date ${foundDate} for effective CID ${effectiveCid} (today: ${today})`);
246
- } else {
247
- logger.log('INFO', `[getUserComputations] Found computation for effective CID ${effectiveCid} on today's date`);
267
+ try {
268
+ // Check if page/computation document exists for this user and date
269
+ // For computations using pages subcollection, checkPiInComputationDate handles it
270
+ // For other computations, check the main document first
271
+ const { found } = await checkPiInComputationDate(
272
+ db,
273
+ insightsCollection,
274
+ resultsSub,
275
+ compsSub,
276
+ category,
277
+ firstCompName,
278
+ dateStr,
279
+ String(effectiveCid),
280
+ logger
281
+ );
282
+
283
+ if (found) {
284
+ foundDate = dateStr;
285
+ if (dateStr !== today) {
286
+ logger.log('INFO', `[getUserComputations] Using fallback date ${foundDate} for effective CID ${effectiveCid} (today: ${today})`);
287
+ } else {
288
+ logger.log('INFO', `[getUserComputations] Found computation for effective CID ${effectiveCid} on today's date`);
289
+ }
290
+ break; // Found user, stop searching
248
291
  }
249
- break; // Found user, stop searching
292
+ } catch (error) {
293
+ // Continue to next date if error
294
+ logger.log('DEBUG', `[getUserComputations] Error checking date ${dateStr}:`, error.message);
295
+ continue;
250
296
  }
251
- } catch (error) {
252
- // Continue to next date if error
253
- logger.log('DEBUG', `[getUserComputations] Error checking date ${dateStr}:`, error.message);
254
- continue;
255
297
  }
256
298
  }
257
299
 
258
300
  if (foundDate) {
259
301
  datesToCheck = [foundDate];
260
302
  } else {
261
- logger.log('WARN', `[getUserComputations] No computation data found for CID ${effectiveCid} in last ${maxDaysBack} days. Frontend will use fallback.`);
303
+ const maxDaysBack = isMetaComputation ? 7 : 30;
304
+ logger.log('WARN', `[getUserComputations] No computation data found for ${isMetaComputation ? 'meta computation' : `CID ${effectiveCid}`} in last ${maxDaysBack} days. Frontend will use fallback.`);
262
305
  return res.status(200).json({
263
306
  status: 'success',
264
307
  userCid: String(effectiveCid),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.579",
3
+ "version": "1.0.580",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [