@gudhub/core 1.2.2 → 1.2.4-beta.0

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.
@@ -0,0 +1,31 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Launch Program",
6
+ "program": "${workspaceFolder}/app.js",
7
+ "request": "launch",
8
+ "skipFiles": [
9
+ "<node_internals>/**"
10
+ ],
11
+ "type": "node"
12
+ },
13
+ {
14
+ "type": "node",
15
+ "request": "launch",
16
+ "runtimeVersion": "16",
17
+ "name": "Launch Program",
18
+ "skipFiles": [
19
+ "<node_internals>/**"
20
+ ],
21
+ "program": "${workspaceFolder}/index.js"
22
+ },
23
+ {
24
+ "type": "node-terminal",
25
+ "name": "Run Script: test",
26
+ "request": "launch",
27
+ "command": "npm run test",
28
+ "cwd": "${workspaceFolder}"
29
+ }
30
+ ]
31
+ }
@@ -78,10 +78,6 @@ export class AppProcessor {
78
78
  }
79
79
  }
80
80
 
81
- async getAppApi(app_id) {
82
- return this.dataService.getApp(app_id);
83
- }
84
-
85
81
  getAppListFromStorage() {
86
82
  return this.storage.getAppsList();
87
83
  }
@@ -186,7 +182,7 @@ export class AppProcessor {
186
182
  for (const app_id of apps_id) {
187
183
  if (app_id != undefined) {
188
184
  try {
189
- const app = await this.getAppApi(app_id);
185
+ const app = await this.dataService.getApp(app_id);
190
186
  if (app) {
191
187
  app.items_object = {};
192
188
 
@@ -259,7 +255,7 @@ export class AppProcessor {
259
255
  let app = this.getAppFromStorage(app_id);
260
256
  if (app) return app;
261
257
 
262
- let receivedApp = await this.getAppApi(app_id);
258
+ let receivedApp = await this.dataService.getApp(app_id);
263
259
  if (!receivedApp) return;
264
260
 
265
261
  //!!! temporary check !!!! if app has chanks property then we start getting it
@@ -33,39 +33,55 @@ export class IndexedDBAppService extends AppDataService {
33
33
 
34
34
 
35
35
  async getApp(id) {
36
+ if (this.requestCache.has(id)) return this.requestCache.get(id);
37
+
36
38
  let dataServiceRequest = this.dataService.getApp(id);
37
39
 
38
40
  dataServiceRequest.then(data => this.putApp(id, data));
39
41
 
40
42
  try {
41
- const db = await this.openDatabase();
42
- const transaction = db.transaction(this.store, "readonly");
43
- const store = transaction.objectStore(this.store);
44
-
45
- const storeRequest = store.get(id);
46
-
47
- return await new Promise((resolve, reject) => {
48
- storeRequest.onsuccess = (e) => {
49
-
50
- let cachedData = e.target.result;
51
-
52
- if (
53
- !cachedData
54
- ) {
55
- reject();
56
- }
57
-
58
- if (
59
- cachedData
60
- ) {
43
+ let self = this;
44
+
45
+ let pr = new Promise(async (resolve, reject) => {
46
+ try {
47
+ const db = await self.openDatabase();
48
+ const transaction = db.transaction(self.store, "readonly");
49
+ const store = transaction.objectStore(self.store);
50
+
51
+ const storeRequest = store.get(id);
61
52
 
62
- resolve(cachedData);
63
- }
64
- };
53
+ storeRequest.onsuccess = (e) => {
65
54
 
66
- storeRequest.onerror = reject
55
+ let cachedData = e.target.result;
56
+
57
+ if (
58
+ !cachedData
59
+ ) {
60
+ reject();
61
+ }
62
+
63
+ if (
64
+ cachedData
65
+ ) {
66
+ resolve(cachedData);
67
+ }
68
+ };
69
+
70
+ storeRequest.onerror = reject
71
+ } catch (error) {
72
+ reject();
73
+ }
67
74
  });
75
+
76
+ self.requestCache.set(id, pr);
77
+
78
+ await pr;
79
+
80
+ return pr;
81
+
68
82
  } catch(e) {
83
+ this.requestCache.set(id, dataServiceRequest);
84
+
69
85
  return dataServiceRequest;
70
86
  }
71
87
  }
@@ -57,41 +57,59 @@ export class IndexedDBChunkService extends ChunkDataService {
57
57
 
58
58
 
59
59
  async getChunk(app_id, id) {
60
+ if (this.requestCache.has(id)) return this.requestCache.get(id);
61
+
60
62
  try {
61
- const db = await this.openDatabase();
62
- const transaction = db.transaction(this.store, "readonly");
63
- const store = transaction.objectStore(this.store);
64
-
65
- const storeRequest = store.get(id);
66
-
67
- return await new Promise((resolve, reject) => {
68
- storeRequest.onsuccess = (e) => {
69
-
70
- let cachedData = e.target.result;
71
-
72
- if (
73
- !cachedData
74
- ) {
75
- reject();
76
- }
77
-
78
- if (
79
- cachedData
80
- ) {
63
+ let self = this;
64
+
65
+ let pr = new Promise(async (resolve, reject) => {
66
+ try {
67
+ const db = await self.openDatabase();
68
+ const transaction = db.transaction(self.store, "readonly");
69
+ const store = transaction.objectStore(self.store);
70
+
71
+ const storeRequest = store.get(id);
81
72
 
82
- resolve(cachedData);
83
- }
84
- };
73
+ storeRequest.onsuccess = (e) => {
85
74
 
86
- storeRequest.onerror = reject
75
+ let cachedData = e.target.result;
76
+
77
+ if (
78
+ !cachedData
79
+ ) {
80
+ reject();
81
+ }
82
+
83
+ if (
84
+ cachedData
85
+ ) {
86
+
87
+ resolve(cachedData);
88
+ }
89
+ };
90
+
91
+ storeRequest.onerror = reject
92
+ } catch (error) {
93
+ reject();
94
+ }
87
95
  });
96
+
97
+ self.requestCache.set(id, pr);
98
+
99
+ await pr;
100
+
101
+ return pr;
102
+
88
103
  } catch(e) {
89
- let res = await this.dataService.getChunk(app_id, id);
104
+ let reqPrms = this.dataService.getChunk(app_id, id);
90
105
 
91
- await this.putChunk(id, res);
92
-
106
+ this.requestCache.set(id, reqPrms);
107
+
108
+ let res = await reqPrms;
109
+
110
+ this.putChunk(id, res);
93
111
 
94
- return res;
112
+ return reqPrms;
95
113
  }
96
114
  }
97
115
 
@@ -3,5 +3,7 @@ export class IndexedDBService {
3
3
  this.store = conf.store;
4
4
  this.dbName = conf.dbName;
5
5
  this.dbVersion = conf.dbVersion;
6
+
7
+ this.requestCache = new Map; // id -> promise
6
8
  }
7
9
  }
@@ -5,7 +5,7 @@ export class AppAPI {
5
5
 
6
6
  async getApp(app_id) {
7
7
  return this.req.get({
8
- url: `${this.req.root}/api/app/get`,
8
+ url: `/api/app/get`,
9
9
  params: {
10
10
  app_id: app_id,
11
11
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.2.2",
3
+ "version": "1.2.4-beta.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {