bulltrackers-module 1.0.116 → 1.0.118

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