@gudhub/core 1.2.4-beta.6 → 1.2.4-beta.7

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.
@@ -21,6 +21,8 @@ export class AppProcessor {
21
21
  this.util = util;
22
22
  this.appListeners();
23
23
  this.dataService = dataService;
24
+
25
+ this.appRequestCache = new Map;
24
26
  }
25
27
 
26
28
  async createNewAppApi(app) {
@@ -255,27 +257,42 @@ export class AppProcessor {
255
257
  let app = this.getAppFromStorage(app_id);
256
258
  if (app) return app;
257
259
 
258
- let receivedApp = await this.dataService.getApp(app_id);
259
- if (!receivedApp) return;
260
-
261
- //!!! temporary check !!!! if app has chanks property then we start getting it
262
- if (
263
- receivedApp.chunks &&
264
- receivedApp.chunks.length
265
- ) {
266
- let chunks = await this.chunksManager.getChunks(app_id, receivedApp.chunks);
267
- receivedApp.items_list = this.util.mergeChunks([
268
- ...chunks,
269
- receivedApp,
270
- ]);
271
- }
260
+ if (this.appRequestCache.has(app_id)) return this.appRequestCache.get(app_id);
261
+
262
+ let self = this;
263
+
264
+ let pr = new Promise(async (resolve, reject) => {
265
+ try {
266
+ let receivedApp = await self.dataService.getApp(app_id);
267
+ if (!receivedApp) reject();
268
+
269
+ //!!! temporary check !!!! if app has chanks property then we start getting it
270
+ if (
271
+ receivedApp.chunks &&
272
+ receivedApp.chunks.length
273
+ ) {
274
+ let chunks = await self.chunksManager.getChunks(app_id, receivedApp.chunks);
275
+ receivedApp.items_list = self.util.mergeChunks([
276
+ ...chunks,
277
+ receivedApp,
278
+ ]);
279
+ }
272
280
 
273
- this.saveAppInStorage(receivedApp);
274
- this.ws.addSubscription(app_id);
275
281
 
276
- // This code for trash must be changed
277
- // return trash ? app : {...app, items_list: app.items_list.filter(item => !item.trash)};
278
- return receivedApp;
282
+ // This code for trash must be changed
283
+ // return trash ? app : {...app, items_list: app.items_list.filter(item => !item.trash)};
284
+ resolve(receivedApp);
285
+
286
+ self.saveAppInStorage(receivedApp);
287
+ self.ws.addSubscription(app_id);
288
+ } catch (error) {
289
+ reject();
290
+ }
291
+ });
292
+
293
+ self.appRequestCache.set(app_id, pr);
294
+
295
+ return pr;
279
296
  }
280
297
 
281
298
  async updateApp(app) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.2.4-beta.6",
3
+ "version": "1.2.4-beta.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {