@pioneer-platform/pioneer-cache 1.1.10 → 1.1.12
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.
- package/CHANGELOG.md +16 -0
- package/dist/stores/balance-cache.js +20 -0
- package/dist/stores/price-cache.js +17 -2
- package/package.json +2 -2
- package/src/stores/balance-cache.ts +24 -0
- package/src/stores/price-cache.ts +20 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @pioneer-platform/pioneer-cache
|
|
2
2
|
|
|
3
|
+
## 1.1.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- chore: fix: move @types/pdfkit to dependencies for Docker --production build
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @pioneer-platform/redis-queue@8.12.2
|
|
10
|
+
|
|
11
|
+
## 1.1.11
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- fix: move @types/pdfkit to dependencies for Docker --production build
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @pioneer-platform/redis-queue@8.12.1
|
|
18
|
+
|
|
3
19
|
## 1.1.10
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -227,7 +227,17 @@ class BalanceCache extends base_cache_1.BaseCache {
|
|
|
227
227
|
const fetchPromises = items.map(async (item) => {
|
|
228
228
|
try {
|
|
229
229
|
// Use fetchFresh to get blockchain data and update cache
|
|
230
|
+
log.info(tag, `🔍 Fetching fresh ${item.caip}...`);
|
|
230
231
|
const freshData = await this.fetchFresh({ caip: item.caip, pubkey: item.pubkey });
|
|
232
|
+
log.info(tag, `🔍 fetchFresh returned for ${item.caip}: caip=${freshData.caip}, balance=${freshData.balance}`);
|
|
233
|
+
// CRITICAL FIX: If fetchFresh returned defaultValue with empty CAIP (due to network init failure),
|
|
234
|
+
// restore the actual CAIP so the response isn't filtered out by the SDK
|
|
235
|
+
if (!freshData.caip || freshData.caip === '') {
|
|
236
|
+
log.warn(tag, `⚠️ RESTORING CAIP: fetchFresh returned empty CAIP for ${item.caip} (likely network init failed)`);
|
|
237
|
+
freshData.caip = item.caip;
|
|
238
|
+
freshData.pubkey = item.pubkey;
|
|
239
|
+
log.warn(tag, `⚠️ RESTORED CAIP: ${freshData.caip}`);
|
|
240
|
+
}
|
|
231
241
|
return freshData;
|
|
232
242
|
}
|
|
233
243
|
catch (error) {
|
|
@@ -294,7 +304,17 @@ class BalanceCache extends base_cache_1.BaseCache {
|
|
|
294
304
|
const fetchPromises = missedItems.map(async (item) => {
|
|
295
305
|
try {
|
|
296
306
|
// Use fetchFresh to ensure Redis is updated and requests are deduplicated
|
|
307
|
+
log.info(tag, `🔍 [CACHE MISS] Fetching fresh ${item.caip}...`);
|
|
297
308
|
const freshData = await this.fetchFresh({ caip: item.caip, pubkey: item.pubkey });
|
|
309
|
+
log.info(tag, `🔍 [CACHE MISS] fetchFresh returned for ${item.caip}: caip='${freshData.caip}', balance=${freshData.balance}`);
|
|
310
|
+
// CRITICAL FIX: If fetchFresh returned defaultValue with empty CAIP (due to network init failure),
|
|
311
|
+
// restore the actual CAIP so the response isn't filtered out by the SDK
|
|
312
|
+
if (!freshData.caip || freshData.caip === '') {
|
|
313
|
+
log.warn(tag, `⚠️ [CACHE MISS] RESTORING CAIP: fetchFresh returned empty CAIP for ${item.caip} (likely network init failed)`);
|
|
314
|
+
freshData.caip = item.caip;
|
|
315
|
+
freshData.pubkey = item.pubkey;
|
|
316
|
+
log.warn(tag, `⚠️ [CACHE MISS] RESTORED CAIP: ${freshData.caip}`);
|
|
317
|
+
}
|
|
298
318
|
results[item.index] = freshData;
|
|
299
319
|
}
|
|
300
320
|
catch (error) {
|
|
@@ -167,12 +167,27 @@ class PriceCache extends base_cache_1.BaseCache {
|
|
|
167
167
|
const startTime = Date.now();
|
|
168
168
|
try {
|
|
169
169
|
log.info(tag, `Batch request for ${caips.length} prices`);
|
|
170
|
+
// Validate and filter out invalid CAIPs
|
|
171
|
+
const validCaips = caips.filter((caip, index) => {
|
|
172
|
+
if (!caip || typeof caip !== 'string') {
|
|
173
|
+
log.warn(tag, `Invalid CAIP at index ${index}:`, caip);
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
});
|
|
178
|
+
if (validCaips.length < caips.length) {
|
|
179
|
+
log.warn(tag, `Filtered ${caips.length - validCaips.length} invalid CAIPs from batch request`);
|
|
180
|
+
}
|
|
181
|
+
if (validCaips.length === 0) {
|
|
182
|
+
log.warn(tag, 'No valid CAIPs in batch request');
|
|
183
|
+
return new Map();
|
|
184
|
+
}
|
|
170
185
|
// Get all prices in parallel
|
|
171
|
-
const promises =
|
|
186
|
+
const promises = validCaips.map(caip => this.getPrice(caip, waitForFresh));
|
|
172
187
|
const results = await Promise.all(promises);
|
|
173
188
|
// Build map of caip -> price
|
|
174
189
|
const priceMap = new Map();
|
|
175
|
-
|
|
190
|
+
validCaips.forEach((caip, index) => {
|
|
176
191
|
priceMap.set(caip, results[index]);
|
|
177
192
|
});
|
|
178
193
|
const responseTime = Date.now() - startTime;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/pioneer-cache",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "Unified caching system for Pioneer platform with Redis backend",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@pioneer-platform/loggerdog": "^8.11.0",
|
|
24
|
-
"@pioneer-platform/redis-queue": "^8.12.
|
|
24
|
+
"@pioneer-platform/redis-queue": "^8.12.2",
|
|
25
25
|
"@pioneer-platform/default-redis": "^8.11.7"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -269,7 +269,19 @@ export class BalanceCache extends BaseCache<BalanceData> {
|
|
|
269
269
|
const fetchPromises = items.map(async (item) => {
|
|
270
270
|
try {
|
|
271
271
|
// Use fetchFresh to get blockchain data and update cache
|
|
272
|
+
log.info(tag, `🔍 Fetching fresh ${item.caip}...`);
|
|
272
273
|
const freshData = await this.fetchFresh({ caip: item.caip, pubkey: item.pubkey });
|
|
274
|
+
log.info(tag, `🔍 fetchFresh returned for ${item.caip}: caip=${freshData.caip}, balance=${freshData.balance}`);
|
|
275
|
+
|
|
276
|
+
// CRITICAL FIX: If fetchFresh returned defaultValue with empty CAIP (due to network init failure),
|
|
277
|
+
// restore the actual CAIP so the response isn't filtered out by the SDK
|
|
278
|
+
if (!freshData.caip || freshData.caip === '') {
|
|
279
|
+
log.warn(tag, `⚠️ RESTORING CAIP: fetchFresh returned empty CAIP for ${item.caip} (likely network init failed)`);
|
|
280
|
+
freshData.caip = item.caip;
|
|
281
|
+
freshData.pubkey = item.pubkey;
|
|
282
|
+
log.warn(tag, `⚠️ RESTORED CAIP: ${freshData.caip}`);
|
|
283
|
+
}
|
|
284
|
+
|
|
273
285
|
return freshData;
|
|
274
286
|
} catch (error) {
|
|
275
287
|
log.error(tag, `Failed to fetch fresh ${item.caip}/${item.pubkey}:`, error);
|
|
@@ -346,7 +358,19 @@ export class BalanceCache extends BaseCache<BalanceData> {
|
|
|
346
358
|
const fetchPromises = missedItems.map(async (item) => {
|
|
347
359
|
try {
|
|
348
360
|
// Use fetchFresh to ensure Redis is updated and requests are deduplicated
|
|
361
|
+
log.info(tag, `🔍 [CACHE MISS] Fetching fresh ${item.caip}...`);
|
|
349
362
|
const freshData = await this.fetchFresh({ caip: item.caip, pubkey: item.pubkey });
|
|
363
|
+
log.info(tag, `🔍 [CACHE MISS] fetchFresh returned for ${item.caip}: caip='${freshData.caip}', balance=${freshData.balance}`);
|
|
364
|
+
|
|
365
|
+
// CRITICAL FIX: If fetchFresh returned defaultValue with empty CAIP (due to network init failure),
|
|
366
|
+
// restore the actual CAIP so the response isn't filtered out by the SDK
|
|
367
|
+
if (!freshData.caip || freshData.caip === '') {
|
|
368
|
+
log.warn(tag, `⚠️ [CACHE MISS] RESTORING CAIP: fetchFresh returned empty CAIP for ${item.caip} (likely network init failed)`);
|
|
369
|
+
freshData.caip = item.caip;
|
|
370
|
+
freshData.pubkey = item.pubkey;
|
|
371
|
+
log.warn(tag, `⚠️ [CACHE MISS] RESTORED CAIP: ${freshData.caip}`);
|
|
372
|
+
}
|
|
373
|
+
|
|
350
374
|
results[item.index] = freshData;
|
|
351
375
|
} catch (error) {
|
|
352
376
|
log.error(tag, `Failed to fetch ${item.caip}/${item.pubkey}:`, error);
|
|
@@ -203,13 +203,31 @@ export class PriceCache extends BaseCache<PriceData> {
|
|
|
203
203
|
try {
|
|
204
204
|
log.info(tag, `Batch request for ${caips.length} prices`);
|
|
205
205
|
|
|
206
|
+
// Validate and filter out invalid CAIPs
|
|
207
|
+
const validCaips = caips.filter((caip, index) => {
|
|
208
|
+
if (!caip || typeof caip !== 'string') {
|
|
209
|
+
log.warn(tag, `Invalid CAIP at index ${index}:`, caip);
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (validCaips.length < caips.length) {
|
|
216
|
+
log.warn(tag, `Filtered ${caips.length - validCaips.length} invalid CAIPs from batch request`);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (validCaips.length === 0) {
|
|
220
|
+
log.warn(tag, 'No valid CAIPs in batch request');
|
|
221
|
+
return new Map();
|
|
222
|
+
}
|
|
223
|
+
|
|
206
224
|
// Get all prices in parallel
|
|
207
|
-
const promises =
|
|
225
|
+
const promises = validCaips.map(caip => this.getPrice(caip, waitForFresh));
|
|
208
226
|
const results = await Promise.all(promises);
|
|
209
227
|
|
|
210
228
|
// Build map of caip -> price
|
|
211
229
|
const priceMap = new Map<string, number>();
|
|
212
|
-
|
|
230
|
+
validCaips.forEach((caip, index) => {
|
|
213
231
|
priceMap.set(caip, results[index]);
|
|
214
232
|
});
|
|
215
233
|
|