bulltrackers-module 1.0.670 → 1.0.672

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.
@@ -2050,24 +2050,52 @@ const fetchUserRecommendations = async (db, userId) => {
2050
2050
  const fetchTrendingPopularInvestors = async (db) => {
2051
2051
  // Path: /unified_insights/{DATE}/results/popular-investor/computations/TrendingPopularInvestors
2052
2052
  const today = new Date().toISOString().split('T')[0];
2053
- try {
2054
- const result = await getComputationResults(db, 'TrendingPopularInvestors', today);
2055
- return result.trending || [];
2056
- } catch (e) {
2057
- console.warn(`[Trending] Failed to fetch: ${e.message}`);
2058
- return [];
2053
+
2054
+ // Try today first, then look back up to 7 days
2055
+ for (let i = 0; i < 7; i++) {
2056
+ const checkDate = new Date(today);
2057
+ checkDate.setDate(checkDate.getDate() - i);
2058
+ const dateKey = checkDate.toISOString().split('T')[0];
2059
+
2060
+ try {
2061
+ const result = await getComputationResults(db, 'TrendingPopularInvestors', dateKey);
2062
+ if (result && result.trending && Array.isArray(result.trending) && result.trending.length > 0) {
2063
+ return result.trending;
2064
+ }
2065
+ } catch (e) {
2066
+ // Continue to next date
2067
+ if (i === 6) {
2068
+ console.warn(`[Trending] Failed to fetch after 7 day lookback: ${e.message}`);
2069
+ }
2070
+ }
2059
2071
  }
2072
+
2073
+ return [];
2060
2074
  };
2061
2075
 
2062
2076
  const fetchPopularInvestorCategories = async (db) => {
2063
2077
  const today = new Date().toISOString().split('T')[0];
2064
- try {
2065
- const result = await getComputationResults(db, 'PopularInvestorCategories', today);
2066
- return result.categories || {};
2067
- } catch (e) {
2068
- console.warn(`[Categories] Failed to fetch: ${e.message}`);
2069
- return {};
2078
+
2079
+ // Try today first, then look back up to 7 days
2080
+ for (let i = 0; i < 7; i++) {
2081
+ const checkDate = new Date(today);
2082
+ checkDate.setDate(checkDate.getDate() - i);
2083
+ const dateKey = checkDate.toISOString().split('T')[0];
2084
+
2085
+ try {
2086
+ const result = await getComputationResults(db, 'PopularInvestorCategories', dateKey);
2087
+ if (result && result.categories && typeof result.categories === 'object' && Object.keys(result.categories).length > 0) {
2088
+ return result.categories;
2089
+ }
2090
+ } catch (e) {
2091
+ // Continue to next date
2092
+ if (i === 6) {
2093
+ console.warn(`[Categories] Failed to fetch after 7 day lookback: ${e.message}`);
2094
+ }
2095
+ }
2070
2096
  }
2097
+
2098
+ return {};
2071
2099
  };
2072
2100
 
2073
2101
 
@@ -80,16 +80,13 @@ function checkRootDependencies(calcManifest, rootDataStatus) {
80
80
  else missingKey = key;
81
81
  }
82
82
 
83
- // 2. Check Availability (with Optimistic Series Fallback)
83
+ // 2. Check Availability
84
+ // [FIX] Removed Optimistic Series Fallback.
85
+ // Just because we want history (series) doesn't mean the data type exists for this date.
84
86
  if (isAvailable) {
85
87
  available.push(dep);
86
88
  } else {
87
- // [OPTIMIZATION] If series data is requested, we can sometimes proceed without the daily snapshot
88
- if (calcManifest.rootDataSeries?.[dep]) {
89
- available.push(dep);
90
- } else {
91
- missing.push(missingKey);
92
- }
89
+ missing.push(missingKey);
93
90
  }
94
91
  }
95
92
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.670",
3
+ "version": "1.0.672",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [