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