bulltrackers-module 1.0.411 → 1.0.412
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.
|
@@ -84,21 +84,10 @@ async function findLatestComputationDate(db, insightsCollection, category, compu
|
|
|
84
84
|
|
|
85
85
|
const computationDoc = await computationRef.get();
|
|
86
86
|
|
|
87
|
+
// Just check if document exists - don't check for CID here
|
|
88
|
+
// We'll check for CID in the calling function after decompression
|
|
87
89
|
if (computationDoc.exists) {
|
|
88
|
-
|
|
89
|
-
// Decompress if needed (handles byte string storage)
|
|
90
|
-
const computationData = tryDecompress(rawData);
|
|
91
|
-
// Check if user's CID exists in the computation result
|
|
92
|
-
const cidStr = String(userCid);
|
|
93
|
-
const hasCid = computationData && computationData[cidStr] !== undefined;
|
|
94
|
-
|
|
95
|
-
if (hasCid) {
|
|
96
|
-
return dateStr; // Found data for this date
|
|
97
|
-
} else if (computationData && typeof computationData === 'object') {
|
|
98
|
-
// Log debug info if document exists but CID not found
|
|
99
|
-
const sampleKeys = Object.keys(computationData).slice(0, 5);
|
|
100
|
-
console.log(`[findLatestComputationDate] Date ${dateStr}: Document exists but CID ${cidStr} not found. Sample keys:`, sampleKeys);
|
|
101
|
-
}
|
|
90
|
+
return dateStr; // Found document for this date
|
|
102
91
|
}
|
|
103
92
|
} catch (error) {
|
|
104
93
|
// Continue to next date if error
|
|
@@ -106,7 +95,7 @@ async function findLatestComputationDate(db, insightsCollection, category, compu
|
|
|
106
95
|
}
|
|
107
96
|
}
|
|
108
97
|
|
|
109
|
-
return null; // No
|
|
98
|
+
return null; // No document found in the last maxDaysBack days
|
|
110
99
|
}
|
|
111
100
|
|
|
112
101
|
/**
|
|
@@ -1387,17 +1376,22 @@ async function getPiProfile(req, res, dependencies, config) {
|
|
|
1387
1376
|
const category = 'popular_investor';
|
|
1388
1377
|
const today = new Date().toISOString().split('T')[0];
|
|
1389
1378
|
|
|
1390
|
-
|
|
1379
|
+
logger.log('INFO', `[getPiProfile] Starting search for PI CID: ${cid}`);
|
|
1380
|
+
|
|
1381
|
+
// Find latest available computation date (just check if document exists, not CID)
|
|
1391
1382
|
const latestDate = await findLatestComputationDate(
|
|
1392
1383
|
db,
|
|
1393
1384
|
insightsCollection,
|
|
1394
1385
|
category,
|
|
1395
1386
|
computationName,
|
|
1396
|
-
|
|
1387
|
+
null, // Don't pass CID - just find if document exists
|
|
1397
1388
|
30
|
|
1398
1389
|
);
|
|
1399
1390
|
|
|
1391
|
+
logger.log('INFO', `[getPiProfile] Latest computation date found: ${latestDate || 'NONE'}`);
|
|
1392
|
+
|
|
1400
1393
|
if (!latestDate) {
|
|
1394
|
+
logger.log('WARN', `[getPiProfile] No computation document found for ${computationName} in last 30 days`);
|
|
1401
1395
|
return res.status(404).json({
|
|
1402
1396
|
error: "Profile data not available",
|
|
1403
1397
|
message: "No computation results found for this Popular Investor"
|
|
@@ -1412,9 +1406,12 @@ async function getPiProfile(req, res, dependencies, config) {
|
|
|
1412
1406
|
.collection(compsSub)
|
|
1413
1407
|
.doc(computationName);
|
|
1414
1408
|
|
|
1409
|
+
logger.log('INFO', `[getPiProfile] Fetching document at path: ${insightsCollection}/${latestDate}/${resultsSub}/${category}/${compsSub}/${computationName}`);
|
|
1410
|
+
|
|
1415
1411
|
const computationDoc = await computationRef.get();
|
|
1416
1412
|
|
|
1417
1413
|
if (!computationDoc.exists) {
|
|
1414
|
+
logger.log('WARN', `[getPiProfile] Document does not exist at expected path`);
|
|
1418
1415
|
return res.status(404).json({
|
|
1419
1416
|
error: "Profile data not found",
|
|
1420
1417
|
message: "Computation document does not exist"
|
|
@@ -1425,6 +1422,7 @@ async function getPiProfile(req, res, dependencies, config) {
|
|
|
1425
1422
|
const rawData = computationDoc.data();
|
|
1426
1423
|
const wasCompressed = rawData && rawData._compressed === true;
|
|
1427
1424
|
logger.log('INFO', `[getPiProfile] Document exists. Was compressed: ${wasCompressed}, CID being searched: ${cid}`);
|
|
1425
|
+
logger.log('INFO', `[getPiProfile] Raw data keys:`, rawData ? Object.keys(rawData).slice(0, 10) : 'NO DATA');
|
|
1428
1426
|
|
|
1429
1427
|
const computationData = tryDecompress(rawData);
|
|
1430
1428
|
|
|
@@ -1443,26 +1441,30 @@ async function getPiProfile(req, res, dependencies, config) {
|
|
|
1443
1441
|
// Log full decompressed data (will be large but needed for debugging)
|
|
1444
1442
|
logger.log('INFO', `[getPiProfile] FULL DECOMPRESSED DOCUMENT CONTENTS:`, JSON.stringify(computationData, null, 2));
|
|
1445
1443
|
|
|
1446
|
-
const
|
|
1444
|
+
const cidStr = String(cid);
|
|
1445
|
+
const profileData = computationData && typeof computationData === 'object' ? computationData[cidStr] : undefined;
|
|
1447
1446
|
|
|
1448
1447
|
if (!profileData) {
|
|
1449
1448
|
// Additional debug info in error response
|
|
1450
1449
|
const availableCids = computationData && typeof computationData === 'object' ? Object.keys(computationData).slice(0, 20) : [];
|
|
1451
|
-
logger.log('WARN', `[getPiProfile] CID ${cid} not found in computation data. Available CIDs (sample):`, availableCids);
|
|
1450
|
+
logger.log('WARN', `[getPiProfile] CID ${cid} (as string: "${cidStr}") not found in computation data. Available CIDs (sample):`, availableCids);
|
|
1452
1451
|
|
|
1453
1452
|
return res.status(404).json({
|
|
1454
1453
|
error: "Profile data not found",
|
|
1455
1454
|
message: "No data for this Popular Investor in computation results",
|
|
1456
1455
|
debug: {
|
|
1457
|
-
searchedCid:
|
|
1456
|
+
searchedCid: cidStr,
|
|
1458
1457
|
wasCompressed: wasCompressed,
|
|
1459
1458
|
totalKeysInDocument: computationData && typeof computationData === 'object' ? Object.keys(computationData).length : 0,
|
|
1460
1459
|
sampleAvailableCids: availableCids,
|
|
1461
|
-
dataDate: latestDate
|
|
1460
|
+
dataDate: latestDate,
|
|
1461
|
+
documentPath: `${insightsCollection}/${latestDate}/${resultsSub}/${category}/${compsSub}/${computationName}`
|
|
1462
1462
|
}
|
|
1463
1463
|
});
|
|
1464
1464
|
}
|
|
1465
1465
|
|
|
1466
|
+
logger.log('SUCCESS', `[getPiProfile] Found profile data for CID ${cid} from date ${latestDate}`);
|
|
1467
|
+
|
|
1466
1468
|
return res.status(200).json({
|
|
1467
1469
|
status: 'success',
|
|
1468
1470
|
cid: String(cid),
|