bulltrackers-module 1.0.704 → 1.0.706

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.
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @fileoverview Executor for "Standard" (User-Level) calculations.
3
3
  * REFACTORED: Hoisted data loading, centralized Series/Root logic.
4
+ * UPDATED: Calls getResult() on computations to trigger summary logging.
5
+ * FIXED: Force-increments shard indexes after every flush to prevent batch overwrites.
4
6
  */
5
7
  const { normalizeName, getEarliestDataDates } = require('../utils/utils');
6
8
  const { streamPortfolioData, streamHistoryData, getPortfolioPartRefs, getHistoryPartRefs } = require('../utils/data_loader');
@@ -80,8 +82,6 @@ class StandardExecutor {
80
82
  const loader = new CachedDataLoader(config, deps);
81
83
 
82
84
  // --- 1. PRE-LOAD GLOBAL DATA (Hoisted) ---
83
- // Load all "Singleton" datasets once (Ratings, Rankings, Series, Mappings)
84
- // instead of checking/loading per-user inside the loop.
85
85
  const startSetup = performance.now();
86
86
 
87
87
  const [
@@ -268,8 +268,22 @@ class StandardExecutor {
268
268
  // =========================================================================
269
269
  static async flushBuffer(state, dateStr, passName, config, deps, shardMap, stats, mode, skipStatus, isInitial) {
270
270
  const transformedState = {};
271
+ const activeCalcs = [];
272
+
271
273
  for (const [name, inst] of Object.entries(state)) {
272
- let data = inst.results || {};
274
+ // [FIX 1] Allow computations to finalize/log summary stats via getResult()
275
+ let data;
276
+ if (typeof inst.getResult === 'function') {
277
+ data = await inst.getResult();
278
+ } else {
279
+ data = inst.results || {};
280
+ }
281
+
282
+ // Track active calculations to increment their shards later
283
+ if (Object.keys(data).length > 0) {
284
+ activeCalcs.push(name);
285
+ }
286
+
273
287
  // Pivot user-date structure if needed
274
288
  const first = Object.keys(data)[0];
275
289
  if (first && data[first] && typeof data[first] === 'object' && /^\d{4}-\d{2}-\d{2}$/.test(Object.keys(data[first])[0])) {
@@ -285,8 +299,19 @@ class StandardExecutor {
285
299
  transformedState[name] = { manifest: inst.manifest, getResult: async () => data, _executionStats: stats[name] };
286
300
  inst.results = {}; // Clear buffer
287
301
  }
302
+
288
303
  const res = await commitResults(transformedState, dateStr, passName, config, deps, skipStatus, { flushMode: mode, shardIndexes: shardMap, isInitialWrite: isInitial });
304
+
305
+ // Update shardMap from result
289
306
  if (res.shardIndexes) Object.assign(shardMap, res.shardIndexes);
307
+
308
+ // [FIX 2] Force increment shard indexes for active calculations.
309
+ // This ensures the NEXT batch writes to a NEW shard (e.g. results_1)
310
+ // instead of overwriting the current one (results_0).
311
+ activeCalcs.forEach(name => {
312
+ shardMap[name] = (shardMap[name] || 0) + 1;
313
+ });
314
+
290
315
  return res;
291
316
  }
292
317
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.704",
3
+ "version": "1.0.706",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [