bulltrackers-module 1.0.672 → 1.0.673

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.
@@ -2049,53 +2049,27 @@ const fetchUserRecommendations = async (db, userId) => {
2049
2049
 
2050
2050
  const fetchTrendingPopularInvestors = async (db) => {
2051
2051
  // Path: /unified_insights/{DATE}/results/popular-investor/computations/TrendingPopularInvestors
2052
+ // Simple fetch - data exists in pointer document (small size, not compressed/sharded)
2052
2053
  const today = new Date().toISOString().split('T')[0];
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
- }
2054
+ try {
2055
+ const result = await getComputationResults(db, 'TrendingPopularInvestors', today);
2056
+ return result.trending || [];
2057
+ } catch (e) {
2058
+ console.warn(`[Trending] Failed to fetch: ${e.message}`);
2059
+ return [];
2071
2060
  }
2072
-
2073
- return [];
2074
2061
  };
2075
2062
 
2076
2063
  const fetchPopularInvestorCategories = async (db) => {
2064
+ // Data exists compressed in pointer document at /unified_insights/{DATE}/results/popular-investor/computations/PopularInvestorCategories
2077
2065
  const today = new Date().toISOString().split('T')[0];
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
- }
2066
+ try {
2067
+ const result = await getComputationResults(db, 'PopularInvestorCategories', today);
2068
+ return result.categories || {};
2069
+ } catch (e) {
2070
+ console.warn(`[Categories] Failed to fetch: ${e.message}`);
2071
+ return {};
2096
2072
  }
2097
-
2098
- return {};
2099
2073
  };
2100
2074
 
2101
2075
 
@@ -209,11 +209,77 @@ router.get('/computations', async (req, res) => {
209
209
  const results = {};
210
210
  for (const compName of computationNames) {
211
211
  try {
212
- const data = await getComputationResults(db, compName, targetDate, userId);
212
+ let data = await getComputationResults(db, compName, targetDate, userId);
213
+
214
+ // For RecommendedPopularInvestors: Ensure data contains the signed-in user's CID
215
+ // If not found, look back up to 7 days to find this specific user's data
216
+ if (compName === 'RecommendedPopularInvestors' && mode === 'latest') {
217
+ const userCidStr = String(userId);
218
+ let foundUserData = false;
219
+
220
+ // Check if current result contains this user's data
221
+ if (data && typeof data === 'object') {
222
+ // For standard mode: data is { [userId]: recommendations[] }
223
+ if (data[userCidStr] && Array.isArray(data[userCidStr])) {
224
+ foundUserData = true;
225
+ }
226
+ // For page mode: data is array of { date, data: {...} }
227
+ else if (Array.isArray(data) && data.length > 0) {
228
+ // Check if any entry has this user's data
229
+ for (const entry of data) {
230
+ if (entry.data && entry.data[userCidStr]) {
231
+ foundUserData = true;
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ }
237
+
238
+ // If user's data not found, look back up to 7 days
239
+ if (!foundUserData) {
240
+ for (let i = 1; i <= 7; i++) {
241
+ const checkDate = new Date(targetDate);
242
+ checkDate.setDate(checkDate.getDate() - i);
243
+ const dateKey = checkDate.toISOString().split('T')[0];
244
+
245
+ try {
246
+ const backData = await getComputationResults(db, compName, dateKey, userId);
247
+ if (backData && typeof backData === 'object') {
248
+ // Check if this date has the user's data
249
+ if (backData[userCidStr] && Array.isArray(backData[userCidStr])) {
250
+ data = backData;
251
+ foundUserData = true;
252
+ break;
253
+ }
254
+ // For page mode
255
+ else if (Array.isArray(backData) && backData.length > 0) {
256
+ for (const entry of backData) {
257
+ if (entry.data && entry.data[userCidStr]) {
258
+ data = backData;
259
+ foundUserData = true;
260
+ break;
261
+ }
262
+ }
263
+ if (foundUserData) break;
264
+ }
265
+ }
266
+ } catch (e) {
267
+ // Continue to next date
268
+ }
269
+ }
270
+ }
271
+
272
+ // Only return data if it contains this user's recommendations
273
+ if (!foundUserData) {
274
+ results[compName] = null;
275
+ continue;
276
+ }
277
+ }
278
+
213
279
  results[compName] = data;
214
280
  } catch (error) {
215
- // If latest mode and today fails, try yesterday
216
- if (mode === 'latest') {
281
+ // If latest mode and today fails, try yesterday (for non-RecommendedPopularInvestors)
282
+ if (mode === 'latest' && compName !== 'RecommendedPopularInvestors') {
217
283
  try {
218
284
  const yesterday = new Date();
219
285
  yesterday.setDate(yesterday.getDate() - 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.672",
3
+ "version": "1.0.673",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [