@gudhub/core 1.2.4-beta.25 → 1.2.4-beta.27

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.
@@ -307,6 +307,27 @@ export class IndexedDBAppServiceForWorker extends AppDataService {
307
307
  // });
308
308
  // }
309
309
 
310
+
311
+ async getAppWithoutProcessing(id) {
312
+ let data = await this.dataService.getAppWithoutProcessing(id);
313
+
314
+ await this.putApp(id, data);
315
+
316
+ return data;
317
+ }
318
+
319
+ // this returns data for specific chunks + app request data
320
+ // async getAppWithSpecificChunksList(id, list) {
321
+ // let data = await this.dataService.getAppWithoutProcessing(id);
322
+
323
+ // await self.putApp(id, data);
324
+
325
+
326
+ // let processedData = await self.processRequestedApp(id, data);//here нужно пересмотреть
327
+
328
+ // return processedData;
329
+ // }
330
+
310
331
  async getApp(id) {
311
332
  // if (this.requestCache.has(id)) return this.requestCache.get(id);
312
333
 
@@ -50,7 +50,9 @@ export class IndexedDBManager {
50
50
  // });
51
51
 
52
52
 
53
- this.dbPrms = this.openDB();
53
+ // this.dbPrms = this.openDB();
54
+
55
+ this.db = null;
54
56
 
55
57
 
56
58
  // this.db = this.openDB();
@@ -135,11 +137,11 @@ export class IndexedDBManager {
135
137
  // TODO remove outdated stores before also
136
138
 
137
139
 
138
- // if (this.db) return this.db;
140
+ if (this.db) return this.db;
139
141
 
140
142
  let resolver, rejecter;
141
143
 
142
- this.dbPrms = new Promise((resolve, reject) => {
144
+ let dbPrms = new Promise((resolve, reject) => {
143
145
  resolver = resolve;
144
146
  rejecter = reject;
145
147
  });
@@ -169,7 +171,7 @@ export class IndexedDBManager {
169
171
  // };
170
172
 
171
173
  request.onsuccess = (event) => {
172
- this.db = event.target.result;
174
+ self.db = event.target.result;
173
175
 
174
176
  // let version = this.db.version;
175
177
 
@@ -177,13 +179,15 @@ export class IndexedDBManager {
177
179
  };
178
180
 
179
181
  request.onerror = rejecter;
182
+
183
+ return dbPrms;
180
184
  // });
181
185
  }
182
186
 
183
187
  async executeOperation(storeName, operation) {
184
188
 
185
189
  //this get executed more than 1 time
186
- await this.dbPrms;
190
+ let db = await this.openDB();
187
191
 
188
192
  // if (
189
193
  // !this.db
@@ -195,12 +199,12 @@ export class IndexedDBManager {
195
199
  // await this.db;
196
200
 
197
201
 
198
- let self = this;
202
+ // let self = this;
199
203
 
200
204
  // await this.db;
201
205
 
202
206
  return new Promise((resolve, reject) => {
203
- const transaction = self.db.transaction(storeName, 'readwrite'); //TODO not all operations readwrite
207
+ const transaction = db.transaction(storeName, 'readwrite'); //TODO not all operations readwrite
204
208
  const store = transaction.objectStore(storeName);
205
209
 
206
210
  transaction.oncomplete = () => resolve();
@@ -40,33 +40,66 @@ self.onmessage = async function(e) {
40
40
  let cached = await appDataService.getCached(e.data.id); // merge ?
41
41
 
42
42
 
43
+ let cachedChunksList = cached.chunks;
43
44
 
44
- // TODO this is repetitive operation for getCached, maybe put all code in process or in getCached
45
45
 
46
- let res = await chunkDataService.getCachedMergedChunk(e.data.id, cached.chunks);
46
+ let nextVersion = await appDataService.getAppWithoutProcessing(e.data.id);
47
47
 
48
- // if (!res) res = [];
49
48
 
49
+ let isMergedChunkUpdated = true;
50
50
 
51
- // TODO check that res always exists
51
+
52
+ if (
53
+ cachedChunksList.length != nextVersion.chunks.length
54
+ ) isMergedChunkUpdated = false;
55
+
56
+
57
+ if (
58
+ nextVersion.chunks.some(entry => !cachedChunksList.includes(entry))
59
+ ) isMergedChunkUpdated = false;
52
60
 
53
61
 
54
62
  if (
55
- res
63
+ !isMergedChunkUpdated
56
64
  ) {
57
- cached.items_list = await gudhub.util.mergeChunks([
58
- // cachedApp,
59
- res,
60
- cached,
61
- ]);
62
- } else {
63
- // sentData.items_list = await this.gudhub.util.mergeChunks([
64
- // cachedApp,
65
- // sentData,
66
- // ]);
65
+
66
+ // TODO this is repetitive operation for getCached, maybe put all code in process or in getCached
67
+
68
+ let res = await chunkDataService.getCachedMergedChunk(e.data.id, cached.chunks);
69
+
70
+ // if (!res) res = [];
71
+
72
+
73
+ // // TODO check that res always exists
74
+
75
+
76
+ if (
77
+ res
78
+ ) {
79
+ cached.items_list = await gudhub.util.mergeChunks([
80
+ // cachedApp,
81
+ res,
82
+ cached,
83
+ ]);
84
+ } else {
85
+ // sentData.items_list = await this.gudhub.util.mergeChunks([
86
+ // cachedApp,
87
+ // sentData,
88
+ // ]);
89
+ }
90
+
91
+ // nextVersion = await appDataService.getAppWithSpecificChunksList(e.data.id, newChunksList); //todo check that here most recent always
92
+ nextVersion = await appDataService.getApp(e.data.id); //todo check that here most recent always
93
+
94
+
95
+ //TODO тут достаточно сравнить новые чанки+апп и закешированный апп, тогда будет сгенерирована вся инфа о новых данных
96
+
97
+
98
+ // return;
67
99
  }
68
100
 
69
- let nextVersion = await appDataService.getApp(e.data.id); //todo check that here most recent always
101
+
102
+
70
103
 
71
104
 
72
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.2.4-beta.25",
3
+ "version": "1.2.4-beta.27",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {