bulltrackers-module 1.0.570 → 1.0.571
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.
|
@@ -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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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 (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
}
|
|
192
|
-
|
|
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
|
-
}
|
|
195
|
-
|
|
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);
|