bulltrackers-module 1.0.441 → 1.0.443
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.
|
@@ -1668,25 +1668,57 @@ async function checkPiInComputationDate(db, insightsCollection, resultsSub, comp
|
|
|
1668
1668
|
return { found: false, profileData: null, computationData: null };
|
|
1669
1669
|
}
|
|
1670
1670
|
|
|
1671
|
-
// Decompress if needed
|
|
1672
1671
|
const rawData = computationDoc.data();
|
|
1673
|
-
let computationData =
|
|
1674
|
-
|
|
1675
|
-
//
|
|
1676
|
-
if (
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1672
|
+
let computationData = null;
|
|
1673
|
+
|
|
1674
|
+
// Check if data is sharded
|
|
1675
|
+
if (rawData._sharded === true && rawData._shardCount) {
|
|
1676
|
+
// Data is stored in shards - read all shards and merge
|
|
1677
|
+
const shardsCol = computationRef.collection('_shards');
|
|
1678
|
+
const shardCount = rawData._shardCount;
|
|
1679
|
+
|
|
1680
|
+
logger.log('INFO', `[checkPiInComputationDate] Reading ${shardCount} shards for date ${dateStr}`);
|
|
1681
|
+
|
|
1682
|
+
computationData = {};
|
|
1683
|
+
|
|
1684
|
+
// Read all shards (shard_0, shard_1, ..., shard_N-1)
|
|
1685
|
+
for (let i = 0; i < shardCount; i++) {
|
|
1686
|
+
const shardDoc = await shardsCol.doc(`shard_${i}`).get();
|
|
1687
|
+
if (shardDoc.exists) {
|
|
1688
|
+
const shardData = shardDoc.data();
|
|
1689
|
+
// Merge shard data into computationData
|
|
1690
|
+
Object.assign(computationData, shardData);
|
|
1691
|
+
} else {
|
|
1692
|
+
logger.log('WARN', `[checkPiInComputationDate] Shard shard_${i} missing for date ${dateStr}`);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
} else {
|
|
1696
|
+
// Data is in the main document (compressed or raw)
|
|
1697
|
+
computationData = tryDecompress(rawData);
|
|
1698
|
+
|
|
1699
|
+
// Handle string decompression result
|
|
1700
|
+
if (typeof computationData === 'string') {
|
|
1701
|
+
try {
|
|
1702
|
+
computationData = JSON.parse(computationData);
|
|
1703
|
+
} catch (e) {
|
|
1704
|
+
logger.log('WARN', `[checkPiInComputationDate] Failed to parse decompressed string for date ${dateStr}:`, e.message);
|
|
1705
|
+
return { found: false, profileData: null, computationData: null };
|
|
1706
|
+
}
|
|
1682
1707
|
}
|
|
1683
1708
|
}
|
|
1684
1709
|
|
|
1685
1710
|
// Check if CID exists in the computation data
|
|
1686
1711
|
if (computationData && typeof computationData === 'object' && !Array.isArray(computationData)) {
|
|
1712
|
+
// Filter out metadata keys that start with underscore
|
|
1713
|
+
const cids = Object.keys(computationData).filter(key => !key.startsWith('_'));
|
|
1714
|
+
|
|
1715
|
+
// Check if the requested CID exists
|
|
1687
1716
|
const profileData = computationData[cidStr];
|
|
1688
1717
|
if (profileData) {
|
|
1718
|
+
logger.log('INFO', `[checkPiInComputationDate] Found CID ${cidStr} in date ${dateStr} (total CIDs: ${cids.length})`);
|
|
1689
1719
|
return { found: true, profileData, computationData };
|
|
1720
|
+
} else {
|
|
1721
|
+
logger.log('INFO', `[checkPiInComputationDate] CID ${cidStr} not found in date ${dateStr}. Available CIDs: ${cids.slice(0, 10).join(', ')}${cids.length > 10 ? '...' : ''}`);
|
|
1690
1722
|
}
|
|
1691
1723
|
}
|
|
1692
1724
|
|
|
@@ -1795,8 +1827,11 @@ async function getPiProfile(req, res, dependencies, config) {
|
|
|
1795
1827
|
logger
|
|
1796
1828
|
);
|
|
1797
1829
|
|
|
1830
|
+
// Filter out metadata keys (those starting with _) when listing available CIDs
|
|
1798
1831
|
const allAvailableCids = latestResult.computationData && typeof latestResult.computationData === 'object' && !Array.isArray(latestResult.computationData)
|
|
1799
|
-
? Object.keys(latestResult.computationData)
|
|
1832
|
+
? Object.keys(latestResult.computationData)
|
|
1833
|
+
.filter(key => !key.startsWith('_'))
|
|
1834
|
+
.sort()
|
|
1800
1835
|
: [];
|
|
1801
1836
|
|
|
1802
1837
|
return res.status(404).json({
|
|
@@ -295,10 +295,39 @@ async function getPiFetchStatus(req, res, dependencies, config) {
|
|
|
295
295
|
|
|
296
296
|
const doc = await docRef.get();
|
|
297
297
|
if (doc.exists) {
|
|
298
|
-
const
|
|
299
|
-
|
|
298
|
+
const docData = doc.data();
|
|
299
|
+
let mergedData = null;
|
|
300
300
|
|
|
301
|
-
if
|
|
301
|
+
// Check if data is sharded
|
|
302
|
+
if (docData._sharded === true && docData._shardCount) {
|
|
303
|
+
// Data is stored in shards - read all shards and merge
|
|
304
|
+
const shardsCol = docRef.collection('_shards');
|
|
305
|
+
const shardsSnapshot = await shardsCol.get();
|
|
306
|
+
|
|
307
|
+
if (!shardsSnapshot.empty) {
|
|
308
|
+
mergedData = {};
|
|
309
|
+
for (const shardDoc of shardsSnapshot.docs) {
|
|
310
|
+
const shardData = shardDoc.data();
|
|
311
|
+
Object.assign(mergedData, shardData);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
// Data is in the main document (compressed or not)
|
|
316
|
+
const { tryDecompress } = require('./data_helpers');
|
|
317
|
+
mergedData = tryDecompress(docData);
|
|
318
|
+
|
|
319
|
+
// Handle string decompression result
|
|
320
|
+
if (typeof mergedData === 'string') {
|
|
321
|
+
try {
|
|
322
|
+
mergedData = JSON.parse(mergedData);
|
|
323
|
+
} catch (e) {
|
|
324
|
+
logger.log('WARN', `[getPiFetchStatus] Failed to parse decompressed string for date ${dateStrFormatted}:`, e.message);
|
|
325
|
+
mergedData = null;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (mergedData && typeof mergedData === 'object' && mergedData[String(piCidNum)]) {
|
|
302
331
|
// Computation completed! Update status
|
|
303
332
|
status = 'completed';
|
|
304
333
|
await requestsSnapshot.docs[0].ref.update({
|