bulltrackers-module 1.0.116 → 1.0.117
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.
|
@@ -772,11 +772,51 @@ async function runMetaComputation(
|
|
|
772
772
|
const summaryData = {};
|
|
773
773
|
|
|
774
774
|
if (result && Object.keys(result).length > 0) {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
775
|
+
|
|
776
|
+
// --- START SHARDING FIX ---
|
|
777
|
+
let isSharded = false;
|
|
778
|
+
const shardedCollections = {
|
|
779
|
+
// Add keys from sharded meta-calcs here
|
|
780
|
+
'sharded_user_profile': config.shardedUserProfileCollection,
|
|
781
|
+
'sharded_user_profitability': config.shardedProfitabilityCollection
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
for (const resultKey in shardedCollections) {
|
|
785
|
+
if (result[resultKey]) {
|
|
786
|
+
isSharded = true;
|
|
787
|
+
const shardCollectionName = shardedCollections[resultKey];
|
|
788
|
+
if (!shardCollectionName) {
|
|
789
|
+
logger.log('ERROR', `[${passName}] Missing config key for sharded collection: ${resultKey}`);
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const shardedData = result[resultKey];
|
|
794
|
+
|
|
795
|
+
for (const shardId in shardedData) {
|
|
796
|
+
const shardDocData = shardedData[shardId];
|
|
797
|
+
if (shardDocData && (Object.keys(shardDocData).length > 0)) {
|
|
798
|
+
const shardRef = db.collection(shardCollectionName).doc(shardId);
|
|
799
|
+
// Use { merge: true } to safely write to sharded docs
|
|
800
|
+
pendingWrites.push({ ref: shardRef, data: shardDocData, merge: true });
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// De-structure the sharded key from the result
|
|
805
|
+
const { [resultKey]: _, ...otherResults } = result;
|
|
806
|
+
result = otherResults; // Re-assign 'result' to be only the non-sharded data
|
|
807
|
+
}
|
|
808
|
+
}
|
|
779
809
|
|
|
810
|
+
// After all sharding is handled, save any *remaining* data
|
|
811
|
+
// (e.g., 'daily_investor_scores' from user-investment-profile)
|
|
812
|
+
if (result && Object.keys(result).length > 0) {
|
|
813
|
+
const computationDocRef = resultsCollectionRef.doc(category)
|
|
814
|
+
.collection(compsSub)
|
|
815
|
+
.doc(calcName);
|
|
816
|
+
pendingWrites.push({ ref: computationDocRef, data: result });
|
|
817
|
+
}
|
|
818
|
+
// --- END SHARDING FIX ---
|
|
819
|
+
|
|
780
820
|
if (!summaryData[category]) summaryData[category] = {};
|
|
781
821
|
summaryData[category][calcName] = true;
|
|
782
822
|
|