roboto-js 1.4.36 → 1.4.38
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/dist/cjs/rbt_api.cjs +23 -17
- package/dist/esm/rbt_api.js +12 -8
- package/package.json +1 -1
- package/src/rbt_api.js +11 -10
package/dist/cjs/rbt_api.cjs
CHANGED
|
@@ -716,7 +716,9 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
716
716
|
defaultOrderBy,
|
|
717
717
|
defaultLimit,
|
|
718
718
|
mergedParams,
|
|
719
|
+
currentTime,
|
|
719
720
|
_paramsKey,
|
|
721
|
+
cacheEntry,
|
|
720
722
|
responsePromise,
|
|
721
723
|
response,
|
|
722
724
|
_args16 = arguments;
|
|
@@ -741,31 +743,35 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
741
743
|
}
|
|
742
744
|
}; // Merge defaults with provided params
|
|
743
745
|
mergedParams = _objectSpread(_objectSpread(_objectSpread({}, defaultOrderBy), defaultLimit), params); // Check cache for an existing request
|
|
746
|
+
currentTime = Date.now();
|
|
744
747
|
_paramsKey = JSON.stringify(mergedParams);
|
|
745
|
-
|
|
746
|
-
|
|
748
|
+
cacheEntry = this.requestCache[_paramsKey];
|
|
749
|
+
if (!(cacheEntry && currentTime - cacheEntry.time < 10000)) {
|
|
750
|
+
_context16.next = 12;
|
|
747
751
|
break;
|
|
748
752
|
}
|
|
749
|
-
|
|
750
|
-
|
|
753
|
+
// 10000 ms = 10 seconds
|
|
754
|
+
console.log("Using cached request for params:", _paramsKey);
|
|
755
|
+
return _context16.abrupt("return", cacheEntry.val);
|
|
756
|
+
case 12:
|
|
751
757
|
// Create the response promise and store it in the cache
|
|
752
|
-
responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams])
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
758
|
+
responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Store the promise along with the current time in the cache
|
|
759
|
+
this.requestCache[_paramsKey] = {
|
|
760
|
+
val: responsePromise,
|
|
761
|
+
time: currentTime
|
|
762
|
+
};
|
|
757
763
|
|
|
758
764
|
// Await the response from the API
|
|
759
|
-
_context16.next =
|
|
765
|
+
_context16.next = 16;
|
|
760
766
|
return responsePromise;
|
|
761
|
-
case
|
|
767
|
+
case 16:
|
|
762
768
|
response = _context16.sent;
|
|
763
769
|
if (!(response.data.ok === false)) {
|
|
764
|
-
_context16.next =
|
|
770
|
+
_context16.next = 19;
|
|
765
771
|
break;
|
|
766
772
|
}
|
|
767
773
|
return _context16.abrupt("return", this._handleError(response));
|
|
768
|
-
case
|
|
774
|
+
case 19:
|
|
769
775
|
// Process items into RbtObject instances
|
|
770
776
|
if (Array.isArray(response.data.items)) {
|
|
771
777
|
response.data.items = response.data.items.map(function (record) {
|
|
@@ -775,16 +781,16 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
775
781
|
});
|
|
776
782
|
}
|
|
777
783
|
return _context16.abrupt("return", response.data.items);
|
|
778
|
-
case
|
|
779
|
-
_context16.prev =
|
|
784
|
+
case 23:
|
|
785
|
+
_context16.prev = 23;
|
|
780
786
|
_context16.t0 = _context16["catch"](1);
|
|
781
787
|
delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
|
|
782
788
|
return _context16.abrupt("return", this._handleError(_context16.t0));
|
|
783
|
-
case
|
|
789
|
+
case 27:
|
|
784
790
|
case "end":
|
|
785
791
|
return _context16.stop();
|
|
786
792
|
}
|
|
787
|
-
}, _callee16, this, [[1,
|
|
793
|
+
}, _callee16, this, [[1, 23]]);
|
|
788
794
|
}));
|
|
789
795
|
function query(_x11) {
|
|
790
796
|
return _query.apply(this, arguments);
|
package/dist/esm/rbt_api.js
CHANGED
|
@@ -357,19 +357,23 @@ export default class RbtApi {
|
|
|
357
357
|
};
|
|
358
358
|
|
|
359
359
|
// Check cache for an existing request
|
|
360
|
+
const currentTime = Date.now();
|
|
360
361
|
const paramsKey = JSON.stringify(mergedParams);
|
|
361
|
-
|
|
362
|
-
|
|
362
|
+
const cacheEntry = this.requestCache[paramsKey];
|
|
363
|
+
if (cacheEntry && currentTime - cacheEntry.time < 10000) {
|
|
364
|
+
// 10000 ms = 10 seconds
|
|
365
|
+
console.log("Using cached request for params:", paramsKey);
|
|
366
|
+
return cacheEntry.val;
|
|
363
367
|
}
|
|
364
368
|
|
|
365
369
|
// Create the response promise and store it in the cache
|
|
366
|
-
const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams])
|
|
367
|
-
// Ensure that the cache is cleaned up after the promise settles
|
|
368
|
-
delete this.requestCache[paramsKey];
|
|
369
|
-
});
|
|
370
|
+
const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
|
|
370
371
|
|
|
371
|
-
// Store the promise in the cache
|
|
372
|
-
this.requestCache[paramsKey] =
|
|
372
|
+
// Store the promise along with the current time in the cache
|
|
373
|
+
this.requestCache[paramsKey] = {
|
|
374
|
+
val: responsePromise,
|
|
375
|
+
time: currentTime
|
|
376
|
+
};
|
|
373
377
|
|
|
374
378
|
// Await the response from the API
|
|
375
379
|
const response = await responsePromise;
|
package/package.json
CHANGED
package/src/rbt_api.js
CHANGED
|
@@ -406,8 +406,9 @@ export default class RbtApi {
|
|
|
406
406
|
* Note: A default orderBy is applied if none is provided, ordering items by 'timeCreated' in descending order.
|
|
407
407
|
*/
|
|
408
408
|
async query(type, params = {}) {
|
|
409
|
+
|
|
409
410
|
try {
|
|
410
|
-
|
|
411
|
+
|
|
411
412
|
params.type = type;
|
|
412
413
|
|
|
413
414
|
// Default ordering and pagination
|
|
@@ -418,20 +419,19 @@ export default class RbtApi {
|
|
|
418
419
|
const mergedParams = { ...defaultOrderBy, ...defaultLimit, ...params };
|
|
419
420
|
|
|
420
421
|
// Check cache for an existing request
|
|
422
|
+
const currentTime = Date.now();
|
|
421
423
|
const paramsKey = JSON.stringify(mergedParams);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
+
const cacheEntry = this.requestCache[paramsKey];
|
|
425
|
+
if (cacheEntry && (currentTime - cacheEntry.time) < 10000) { // 10000 ms = 10 seconds
|
|
426
|
+
console.log("Using cached request for params:", paramsKey);
|
|
427
|
+
return cacheEntry.val;
|
|
424
428
|
}
|
|
425
429
|
|
|
426
430
|
// Create the response promise and store it in the cache
|
|
427
|
-
const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams])
|
|
428
|
-
.finally(() => {
|
|
429
|
-
// Ensure that the cache is cleaned up after the promise settles
|
|
430
|
-
delete this.requestCache[paramsKey];
|
|
431
|
-
});
|
|
431
|
+
const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
|
|
432
432
|
|
|
433
|
-
// Store the promise in the cache
|
|
434
|
-
this.requestCache[paramsKey] = responsePromise;
|
|
433
|
+
// Store the promise along with the current time in the cache
|
|
434
|
+
this.requestCache[paramsKey] = { val: responsePromise, time: currentTime };
|
|
435
435
|
|
|
436
436
|
// Await the response from the API
|
|
437
437
|
const response = await responsePromise;
|
|
@@ -455,6 +455,7 @@ export default class RbtApi {
|
|
|
455
455
|
return this._handleError(e);
|
|
456
456
|
|
|
457
457
|
}
|
|
458
|
+
|
|
458
459
|
}
|
|
459
460
|
|
|
460
461
|
/**
|