bulltrackers-module 1.0.570 → 1.0.572

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.
@@ -250,6 +250,7 @@ function buildManifest(productLinesToRun = [], calculations) {
250
250
  category: folderName === 'core' && metadata.category ? metadata.category : folderName,
251
251
  sourcePackage: folderName,
252
252
  type: metadata.type,
253
+ isPage: metadata.isPage === true,
253
254
  isHistorical: metadata.isHistorical !== undefined ? metadata.isHistorical : false,
254
255
  rootDataDependencies: metadata.rootDataDependencies || [],
255
256
  canHaveMissingRoots: metadata.canHaveMissingRoots || false,
@@ -148,51 +148,70 @@ async function getUserDataStatus(req, res, dependencies, config) {
148
148
  const category = 'popular-investor';
149
149
  const computationName = 'SignedInUserProfileMetrics';
150
150
 
151
- // Find latest computation date
152
- const latestComputationDate = await findLatestComputationDate(
153
- db,
154
- insightsCollection,
155
- resultsSub,
156
- compsSub,
157
- category,
158
- computationName,
159
- effectiveCid,
160
- 30
161
- );
162
-
163
151
  let computationAvailable = false;
164
152
  let computationDate = null;
165
153
  let isComputationFallback = false;
166
154
 
167
- if (latestComputationDate) {
168
- // Check if this specific user exists in the computation
169
- const { found } = await checkPiInComputationDate(
170
- db,
171
- insightsCollection,
172
- resultsSub,
173
- compsSub,
174
- category,
175
- computationName,
176
- latestComputationDate,
177
- String(effectiveCid),
178
- logger
179
- );
155
+ // Search backwards from today to find the latest date where user exists in computation
156
+ // Priority: Today (T) -> Yesterday (T-1) -> Continue backwards up to 30 days
157
+ const maxDaysBack = 30;
158
+ let foundDate = null;
159
+
160
+ for (let daysBack = 0; daysBack < maxDaysBack; daysBack++) {
161
+ const checkDate = new Date();
162
+ checkDate.setDate(checkDate.getDate() - daysBack);
163
+ const dateStr = checkDate.toISOString().split('T')[0];
180
164
 
181
- if (found) {
182
- computationAvailable = true;
183
- computationDate = latestComputationDate;
184
- isComputationFallback = latestComputationDate !== today;
165
+ try {
166
+ // Check if computation document exists for this date
167
+ const computationRef = db.collection(insightsCollection)
168
+ .doc(dateStr)
169
+ .collection(resultsSub)
170
+ .doc(category)
171
+ .collection(compsSub)
172
+ .doc(computationName);
173
+
174
+ const computationDoc = await computationRef.get();
185
175
 
186
- if (isComputationFallback) {
187
- logger.log('INFO', `[getUserDataStatus] Using fallback computation date ${computationDate} for user ${userCid} (today: ${today})`);
188
- } else {
189
- logger.log('INFO', `[getUserDataStatus] Found computation for user ${userCid} on today's date`);
176
+ if (computationDoc.exists) {
177
+ // Computation exists for this date, check if user is in it
178
+ const { found } = await checkPiInComputationDate(
179
+ db,
180
+ insightsCollection,
181
+ resultsSub,
182
+ compsSub,
183
+ category,
184
+ computationName,
185
+ dateStr,
186
+ String(effectiveCid),
187
+ logger
188
+ );
189
+
190
+ if (found) {
191
+ foundDate = dateStr;
192
+ computationAvailable = true;
193
+ computationDate = dateStr;
194
+ isComputationFallback = daysBack > 0;
195
+
196
+ if (isComputationFallback) {
197
+ logger.log('INFO', `[getUserDataStatus] Found computation for user ${userCid} on date ${computationDate} (${daysBack} days back from today: ${today})`);
198
+ } else {
199
+ logger.log('INFO', `[getUserDataStatus] Found computation for user ${userCid} on today's date`);
200
+ }
201
+ break; // Found user, stop searching
202
+ } else {
203
+ logger.log('DEBUG', `[getUserDataStatus] Computation exists for date ${dateStr} but user ${userCid} not found in it, continuing search...`);
204
+ }
190
205
  }
191
- } else {
192
- logger.log('INFO', `[getUserDataStatus] Computation exists for date ${latestComputationDate} but user ${userCid} not found in it`);
206
+ } catch (error) {
207
+ // Continue to next date if error
208
+ logger.log('DEBUG', `[getUserDataStatus] Error checking date ${dateStr}:`, error.message);
209
+ continue;
193
210
  }
194
- } else {
195
- logger.log('INFO', `[getUserDataStatus] No computation found for user ${userCid} in last 30 days`);
211
+ }
212
+
213
+ if (!foundDate) {
214
+ logger.log('INFO', `[getUserDataStatus] No computation found for user ${userCid} in last ${maxDaysBack} days`);
196
215
  }
197
216
 
198
217
  // For backward compatibility, keep portfolioAvailable and historyAvailable
@@ -201,14 +220,22 @@ async function getUserDataStatus(req, res, dependencies, config) {
201
220
  portfolioAvailable: computationAvailable, // Profile page uses computation, not raw portfolio
202
221
  historyAvailable: computationAvailable, // Profile page uses computation, not raw history
203
222
  computationAvailable: computationAvailable, // Explicit computation check
204
- date: computationDate || today,
205
- computationDate: computationDate,
206
- isComputationFallback: isComputationFallback,
207
- requestedDate: today,
223
+ date: computationDate || today, // Use found date or today as fallback
224
+ computationDate: computationDate, // The actual date where computation was found
225
+ isComputationFallback: isComputationFallback, // True if using T-1 or older date
226
+ requestedDate: today, // What date was requested (today)
208
227
  userCid: String(userCid),
209
228
  effectiveCid: String(effectiveCid)
210
229
  };
211
230
 
231
+ if (computationAvailable && isComputationFallback) {
232
+ logger.log('INFO', `[getUserDataStatus] Using fallback date ${computationDate} for CID ${userCid} (requested: ${today})`);
233
+ } else if (computationAvailable) {
234
+ logger.log('INFO', `[getUserDataStatus] Using today's date ${computationDate} for CID ${userCid}`);
235
+ } else {
236
+ logger.log('WARN', `[getUserDataStatus] No computation found for CID ${userCid} in last ${maxDaysBack} days`);
237
+ }
238
+
212
239
  logger.log('INFO', `[getUserDataStatus] Result for CID ${userCid}:`, result);
213
240
 
214
241
  return res.status(200).json(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.570",
3
+ "version": "1.0.572",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [