bulltrackers-module 1.0.150 → 1.0.152

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.
@@ -40,7 +40,7 @@ async function checkRootDataAvailability(dateStr, config, dependencies, earliest
40
40
  if (dateToProcess >= earliestDates.social) {tasks.push(loadDailySocialPostInsights(config, dependencies, dateStr).then(res => {socialData = res;hasSocial = !!res;}));}
41
41
  if (dateToProcess >= earliestDates.history) {tasks.push(getHistoryPartRefs(config, dependencies, dateStr).then(res => {historyRefs = res;hasHistory = !!(res?.length);}));}
42
42
  await Promise.all(tasks);
43
- logger.log('INFO', `[PassRunner] Data availability for ${dateStr}: P:${hasPortfolio}, I:${insightsData_}, S:${socialData_}, H:${hasHistory}`);
43
+ logger.log('INFO', `[PassRunner] Data availability for ${dateStr}: P:${hasPortfolio}, I:${hasInsights}, S:${hasSocial}, H:${hasHistory}`); //Fixed bug, was logging insightsData and socialData objects
44
44
  if (!(hasPortfolio || hasInsights || hasSocial || hasHistory)) { logger.log('WARN', `[PassRunner] No root data at all for ${dateStr}.`); return null; }
45
45
  return { portfolioRefs, todayInsights: insightsData, todaySocialPostInsights: socialData, historyRefs, status: { hasPortfolio, hasInsights, hasSocial, hasHistory } };
46
46
  } catch (err) { logger.log('ERROR', `[PassRunner] Error checking data for ${dateStr}`, { errorMessage: err.message }); return null; }
@@ -111,6 +111,13 @@ async function loadHistoricalData(date, calcs, config, deps, rootData) {
111
111
  const needsYesterdayInsights = calcs.some(c => c.isHistorical && c.rootDataDependencies.includes('insights'));
112
112
  const needsYesterdaySocial = calcs.some(c => c.isHistorical && c.rootDataDependencies.includes('social'));
113
113
 
114
+ // --- ADD THIS ---
115
+ const needsYesterdayPortfolio = calcs.some(c => c.isHistorical && c.rootDataDependencies.includes('portfolio'));
116
+ const prev = new Date(date);
117
+ prev.setUTCDate(prev.getUTCDate() - 1);
118
+ const prevStr = prev.toISOString().slice(0, 10);
119
+ // --- END ADD ---
120
+
114
121
  if(needsYesterdayInsights) {
115
122
  tasks.push((async()=>{ const prev=new Date(date); prev.setUTCDate(prev.getUTCDate()-1); const prevStr=prev.toISOString().slice(0,10);
116
123
  logger.log('INFO', `[PassRunner] Loading YESTERDAY insights data for ${prevStr}`);
@@ -120,6 +127,16 @@ async function loadHistoricalData(date, calcs, config, deps, rootData) {
120
127
  logger.log('INFO', `[PassRunner] Loading YESTERDAY social data for ${prevStr}`);
121
128
  updated.yesterdaySocialPostInsights=await loadDailySocialPostInsights(config,deps,prevStr); })());}
122
129
 
130
+ // --- ADD THIS BLOCK ---
131
+ if(needsYesterdayPortfolio) {
132
+ tasks.push((async()=>{
133
+ logger.log('INFO', `[PassRunner] Getting YESTERDAY portfolio refs for ${prevStr}`);
134
+ // This adds the refs to the 'fullRoot' object for later
135
+ updated.yesterdayPortfolioRefs = await getPortfolioPartRefs(config, deps, prevStr);
136
+ })());
137
+ }
138
+ // --- END ADD ---
139
+
123
140
  await Promise.all(tasks);
124
141
  return updated;
125
142
  }
@@ -131,8 +148,9 @@ async function loadHistoricalData(date, calcs, config, deps, rootData) {
131
148
  * It loads chunks of all three streams, processes UIDs found in the
132
149
  * main (today's portfolio) stream, and then deletes processed users
133
150
  * from the historical maps to free memory.
151
+ * --- FIX: Added portfolioRefs and historyRefs to signature ---
134
152
  */
135
- async function streamAndProcess(dateStr, state, passName, config, deps, rootData) {
153
+ async function streamAndProcess(dateStr, state, passName, config, deps, rootData, portfolioRefs, historyRefs) {
136
154
  const { logger, calculationUtils } = deps;
137
155
  const { todayInsights, yesterdayInsights, todaySocialPostInsights, yesterdaySocialPostInsights } = rootData;
138
156
  const calcsThatStreamPortfolio = Object.values(state).filter(calc => calc && calc.manifest && (calc.manifest.rootDataDependencies.includes('portfolio') || calc.manifest.category === 'speculators'));
@@ -168,8 +186,12 @@ async function streamAndProcess(dateStr, state, passName, config, deps, rootData
168
186
  const needsYesterdayPortfolio = Object.values(state).some(c => c && c.manifest.isHistorical && c.manifest.rootDataDependencies.includes('portfolio'));
169
187
  const needsTodayHistory = Object.values(state).some(c => c && c.manifest.rootDataDependencies.includes('history'));
170
188
 
171
- const yP_iterator = needsYesterdayPortfolio ? streamPortfolioData(config, deps, prevDateStr) : null;
172
- const hT_iterator = needsTodayHistory ? streamHistoryData(config, deps, dateStr) : null;
189
+ // --- FIX: Pass pre-fetched refs to the generators ---
190
+ // Use the refs from fullRoot (which is rootData + yesterdayPortfolioRefs)
191
+ const yP_iterator = needsYesterdayPortfolio ? streamPortfolioData(config, deps, prevDateStr, rootData.yesterdayPortfolioRefs) : null;
192
+ // Use the historyRefs argument
193
+ const hT_iterator = needsTodayHistory ? streamHistoryData(config, deps, dateStr, historyRefs) : null;
194
+ // --- END FIX ---
173
195
 
174
196
  let yesterdayPortfolios = {};
175
197
  let todayHistoryData = {};
@@ -183,7 +205,9 @@ async function streamAndProcess(dateStr, state, passName, config, deps, rootData
183
205
  logger.log('INFO', `[${passName}] Loaded first chunk of today's history.`);
184
206
  }
185
207
 
186
- for await (const chunk of streamPortfolioData(config, deps, dateStr)) {
208
+ // --- FIX: Pass pre-fetched portfolioRefs to the main loop generator ---
209
+ for await (const chunk of streamPortfolioData(config, deps, dateStr, portfolioRefs)) {
210
+ // --- END FIX ---
187
211
 
188
212
  if (yP_iterator) {
189
213
  Object.assign(yesterdayPortfolios, (await yP_iterator.next()).value || {});
@@ -237,7 +261,10 @@ async function runStandardComputationPass(date, calcs, passName, config, deps, r
237
261
  logger.log('INFO', `[${passName}] Running ${dStr} with ${calcs.length} calcs.`);
238
262
  const fullRoot = await loadHistoricalData(date, calcs, config, deps, rootData);
239
263
  const state = initializeCalculators(calcs, logger);
240
- await streamAndProcess(dStr, state, passName, config, deps, fullRoot);
264
+
265
+ // --- FIX: Pass portfolioRefs and historyRefs from rootData ---
266
+ await streamAndProcess(dStr, state, passName, config, deps, fullRoot, rootData.portfolioRefs, rootData.historyRefs);
267
+ // --- END FIX ---
241
268
 
242
269
  let success = 0;
243
270
  const failedCalcs = [];
@@ -2,6 +2,7 @@
2
2
  * @fileoverview Data loader sub-pipes for the Computation System.
3
3
  * REFACTORED: Now stateless and receive dependencies.
4
4
  * --- NEW: Added streamPortfolioData async generator ---
5
+ * --- FIXED: streamPortfolioData and streamHistoryData now accept optional 'providedRefs' ---
5
6
  */
6
7
 
7
8
  // <<< FIX: REMOVED all top-level 'require' and 'dependencies' lines >>>
@@ -173,10 +174,13 @@ async function getHistoryPartRefs(config, deps, dateString) {
173
174
  * @param {object} config - The computation system configuration object.
174
175
  * @param {object} deps - Contains db, logger, calculationUtils.
175
176
  * @param {string} dateString - The date in YYYY-MM-DD format.
177
+ * @param {Array<Firestore.DocumentReference> | null} [providedRefs=null] - Optional pre-fetched refs.
176
178
  */
177
- async function* streamPortfolioData(config, deps, dateString) {
179
+ async function* streamPortfolioData(config, deps, dateString, providedRefs = null) {
178
180
  const { logger } = deps;
179
- const refs = await getPortfolioPartRefs(config, deps, dateString);
181
+ // --- FIX: Use providedRefs if available, otherwise fetch them ---
182
+ const refs = providedRefs || (await getPortfolioPartRefs(config, deps, dateString));
183
+
180
184
  if (refs.length === 0) {
181
185
  logger.log('WARN', `[streamPortfolioData] No portfolio refs found for ${dateString}. Stream is empty.`);
182
186
  return;
@@ -201,10 +205,16 @@ async function* streamPortfolioData(config, deps, dateString) {
201
205
  /**
202
206
  * --- NEW: Stage 8: Stream history data in chunks ---
203
207
  * Streams history data in chunks for a given date.
208
+ * @param {object} config - The computation system configuration object.
209
+ * @param {object} deps - Contains db, logger, calculationUtils.
210
+ * @param {string} dateString - The date in YYYY-MM-DD format.
211
+ * @param {Array<Firestore.DocumentReference> | null} [providedRefs=null] - Optional pre-fetched refs.
204
212
  */
205
- async function* streamHistoryData(config, deps, dateString) {
213
+ async function* streamHistoryData(config, deps, dateString, providedRefs = null) {
206
214
  const { logger } = deps;
207
- const refs = await getHistoryPartRefs(config, deps, dateString); // <-- Uses history refs
215
+ // --- FIX: Use providedRefs if available, otherwise fetch them ---
216
+ const refs = providedRefs || (await getHistoryPartRefs(config, deps, dateString)); // <-- Uses history refs
217
+
208
218
  if (refs.length === 0) {
209
219
  logger.log('WARN', `[streamHistoryData] No history refs found for ${dateString}. Stream is empty.`);
210
220
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.150",
3
+ "version": "1.0.152",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [