@gudhub/core 1.2.4-beta.26 → 1.2.4-beta.28

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.
@@ -24,12 +24,35 @@ export class AppDataService extends DataService {
24
24
  async processRequestedApp(id, sentData) {
25
25
 
26
26
 
27
+ // let
28
+
29
+
30
+ // let chunksHashesToLoad = sentData.chunks;
31
+
32
+ // let chunks = [];
33
+
34
+
35
+ // if (
36
+ // this.chunkDataService.isWithCache()
37
+ // ) {
38
+
39
+ // let cachedMergedChunkData = this.chunkDataService.getCached(id);
40
+
41
+ // }
42
+
43
+
27
44
 
28
-
45
+ // all implementations are without cache for now
29
46
  if (
30
47
  !this.isWithCache()
31
48
  ) {
32
49
 
50
+
51
+ // let resultedMergedChunks = this.chunkDataService.getMergedChunk(id, sentData.chunks);
52
+
53
+
54
+ ///TODO here chunks could be with cache too
55
+
33
56
  // async getChunks(app_id, chunk_ids) {
34
57
  // let chunks = [];
35
58
  // if(chunk_ids){
@@ -78,6 +101,10 @@ export class AppDataService extends DataService {
78
101
 
79
102
 
80
103
 
104
+ throw new Error;
105
+
106
+
107
+
81
108
 
82
109
 
83
110
 
@@ -87,6 +114,17 @@ export class AppDataService extends DataService {
87
114
  let cachedApp = await this.getCached(id); // this should be merged chunk + app from db
88
115
 
89
116
 
117
+ // if (
118
+ // this.chunkDataService.isWithCache()
119
+ // ) {
120
+ // let cachedMergedChunk = this.chunkDataService.getCached();
121
+ // }
122
+
123
+
124
+ // let res = await this.chunkDataService.getMergedChunkForIDList(id, sentData.chunks);
125
+
126
+
127
+
90
128
  // let cachedMergedChunk = await this.chunkDataService.getCachedMergedChunk(id, cachedApp.chunks);
91
129
 
92
130
  if (
@@ -4,7 +4,12 @@ export class ChunkDataService extends DataService {
4
4
  //interface for indexeddb and http services
5
5
 
6
6
 
7
+ //here
7
8
  getMergedChunkForIDList(idList) {
8
9
 
9
10
  }
11
+
12
+ isWithCache() {
13
+ return false;
14
+ }
10
15
  }
@@ -177,6 +177,9 @@ export class IndexedDBAppServiceForWorker extends AppDataService {
177
177
 
178
178
  this.chunkDataService = new IndexedDBChunkService(req, chunksMergeConf, gudhub);
179
179
 
180
+ // let res = await this.chunkDataService.getMergedChunkForIDList(id, sentData.chunks);
181
+
182
+
180
183
 
181
184
 
182
185
  //TODO objectAssignWithOverride here too?
@@ -220,7 +223,7 @@ export class IndexedDBAppServiceForWorker extends AppDataService {
220
223
 
221
224
 
222
225
  isWithCache() {
223
- return true;
226
+ return false;
224
227
  }
225
228
 
226
229
  // getApp(id) {
@@ -339,7 +342,7 @@ export class IndexedDBAppServiceForWorker extends AppDataService {
339
342
  // let dataServiceRequest = this.dataService.getAppWithoutProcessing(id);
340
343
  let data = await this.dataService.getAppWithoutProcessing(id);
341
344
 
342
- await self.putApp(id, data);
345
+ // await self.putApp(id, data);
343
346
 
344
347
  let processedData = await self.processRequestedApp(id, data);//here нужно пересмотреть
345
348
 
@@ -571,6 +574,7 @@ export class IndexedDBAppService extends AppDataService {
571
574
 
572
575
 
573
576
  // todo check this for new code
577
+ // todo outdated code, to remove
574
578
  if (
575
579
  e.data.type == 'processData'
576
580
  ) {
@@ -640,7 +644,7 @@ export class IndexedDBAppService extends AppDataService {
640
644
 
641
645
 
642
646
  isWithCache() {
643
- return true;
647
+ return false; //doesnt use indexeddb
644
648
  }
645
649
 
646
650
  async getApp(id) {//TODO -> get?
@@ -654,7 +658,7 @@ export class IndexedDBAppService extends AppDataService {
654
658
 
655
659
 
656
660
  if (
657
- hasId
661
+ false
658
662
  ) {
659
663
 
660
664
  // let promiseObject = Promise.
@@ -79,6 +79,18 @@ export class IndexedDBChunkService extends ChunkDataService {
79
79
  }
80
80
  }
81
81
 
82
+ isWithCache() {
83
+ return true;
84
+ }
85
+
86
+
87
+ async getMergedChunkForApp(id) {
88
+ // here request api and get chunks list
89
+
90
+ //then perform all required checks for cached chunk and hashes and new hashes
91
+ }
92
+
93
+ //here // TODO replace this with getMergedChunkForApp in future
82
94
  async getMergedChunkForIDList(id, chunkHashesList) {
83
95
 
84
96
 
@@ -88,30 +100,88 @@ export class IndexedDBChunkService extends ChunkDataService {
88
100
 
89
101
 
90
102
  try {
103
+
104
+
105
+ let isCachedValid = true;
106
+
91
107
  let cachedData = await this.storeManager.get(id);
92
108
 
93
109
 
110
+ try {
111
+
112
+ if (chunkHashesList.length < cachedData.hashes.length) throw new Error;
113
+
114
+ for (let hash of cachedData.hashes) {
115
+ if (
116
+ chunkHashesList.indexOf(hash) != cachedData.hashes.indexOf(hash)
117
+ ) isCachedValid = false;
118
+ }
119
+ } catch (error) {
120
+ isCachedValid = false;
121
+ }
122
+
123
+
124
+
125
+
126
+
94
127
  if (
95
- chunkHashesList.every(h1 => cachedData.hashes.includes(h1))
128
+ !isCachedValid
96
129
  ) {
97
- return cachedData.mergedData;
130
+ // todo reload all data
98
131
  }
99
132
 
100
- let newHashes = chunkHashesList.filter(c => !cachedData.hashes.includes(c));
101
133
 
102
134
 
103
- const requests = newHashes.map(hash => this.dataService.getChunk(id, hash));
135
+ let newChunkHashes = [];
136
+ let newChunks = [];
137
+
138
+
139
+
140
+ if (
141
+ chunkHashesList.length > cachedData.hashes.length
142
+ ) {
143
+ newChunkHashes = chunkHashesList.slice(cachedData.hashes.length);
144
+ }
145
+
146
+ if (
147
+ !isCachedValid
148
+ ) {
149
+ newChunkHashes = chunkHashesList;
150
+ }
151
+
152
+ if (
153
+ newChunkHashes.length > 0
154
+ ) {
155
+ const requests = newChunkHashes.map(hash => this.dataService.getChunk(id, hash));
104
156
 
105
- const newChunks = await Promise.all(requests);
157
+ newChunks = await Promise.all(requests);
158
+ }
106
159
 
160
+ let mergedData;
161
+ if (
162
+ !isCachedValid
163
+ ) {
164
+ mergedData = await this.gudhub.util.mergeChunks([
165
+ // cachedData.mergedData,
166
+ ...newChunks,
167
+ ]);
168
+ }
107
169
 
108
- let mergedData = await this.gudhub.util.mergeChunks([
170
+ if (
171
+ isCachedValid
172
+ ) {
173
+ mergedData = await this.gudhub.util.mergeChunks([
109
174
  cachedData.mergedData,
110
175
  ...newChunks,
111
176
  ]);
177
+ }
112
178
 
113
- this.putMergedChunks(id, {hashes: chunkHashesList, mergedData: {items_list: mergedData}});
114
179
 
180
+ if (
181
+ newChunkHashes.length > 0
182
+ ) {
183
+ this.putMergedChunks(id, {hashes: chunkHashesList, mergedData: {items_list: mergedData}});
184
+ }
115
185
 
116
186
  return {items_list: mergedData};
117
187
  } catch (error) {
@@ -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();
@@ -54,6 +54,7 @@ self.onmessage = async function(e) {
54
54
  ) isMergedChunkUpdated = false;
55
55
 
56
56
 
57
+ //TODO here old chunks should be exactly with ids that came from app get request
57
58
  if (
58
59
  nextVersion.chunks.some(entry => !cachedChunksList.includes(entry))
59
60
  ) isMergedChunkUpdated = false;
@@ -148,6 +149,70 @@ self.onmessage = async function(e) {
148
149
  e.data.type === 'requestApp'
149
150
  ) {
150
151
 
152
+ // //todo cached could not exist !!!!!!!!!!!!!!!!!!!
153
+
154
+ // let cached = await appDataService.getCached(e.data.id); // merge ?
155
+
156
+
157
+ // let cachedChunksList = cached.chunks;
158
+
159
+
160
+ // let nextVersion = await appDataService.getAppWithoutProcessing(e.data.id);
161
+
162
+
163
+ // let isMergedChunkUpdated = true;
164
+
165
+
166
+ // if (
167
+ // cachedChunksList.length != nextVersion.chunks.length
168
+ // ) isMergedChunkUpdated = false;
169
+
170
+
171
+ // //TODO here old chunks should be exactly with ids that came from app get request
172
+ // if (
173
+ // nextVersion.chunks.some(entry => !cachedChunksList.includes(entry))
174
+ // ) isMergedChunkUpdated = false;
175
+
176
+
177
+ // if (
178
+ // !isMergedChunkUpdated
179
+ // ) {
180
+
181
+ // // TODO this is repetitive operation for getCached, maybe put all code in process or in getCached
182
+
183
+ // let res = await chunkDataService.getCachedMergedChunk(e.data.id, cached.chunks);
184
+
185
+ // // if (!res) res = [];
186
+
187
+
188
+ // // // TODO check that res always exists
189
+
190
+
191
+ // if (
192
+ // res
193
+ // ) {
194
+ // cached.items_list = await gudhub.util.mergeChunks([
195
+ // // cachedApp,
196
+ // res,
197
+ // cached,
198
+ // ]);
199
+ // } else {
200
+ // // sentData.items_list = await this.gudhub.util.mergeChunks([
201
+ // // cachedApp,
202
+ // // sentData,
203
+ // // ]);
204
+ // }
205
+
206
+ // // nextVersion = await appDataService.getAppWithSpecificChunksList(e.data.id, newChunksList); //todo check that here most recent always
207
+ // nextVersion = await appDataService.getApp(e.data.id); //todo check that here most recent always
208
+
209
+
210
+ // //TODO тут достаточно сравнить новые чанки+апп и закешированный апп, тогда будет сгенерирована вся инфа о новых данных
211
+
212
+
213
+ // // return;
214
+ // }
215
+
151
216
  let data = await appDataService.getApp(e.data.id); //todo check process request method seems there i return cahced version not most recent data from server
152
217
 
153
218
 
@@ -34,9 +34,9 @@ if (
34
34
 
35
35
  if (
36
36
  IS_BROWSER &&
37
- cache_app_requests
37
+ cache_app_requests // todo here outdated approach
38
38
  ) {
39
- AppDataService = IndexedDBAppService;
39
+ AppDataService = IndexedDBAppService; // here will be AppHttpService for browser too, check compatability. Checked. seems different code. IndexedDBAppService uses worker
40
40
  appDataServiceConf = appsConf;
41
41
  } else {
42
42
  AppDataService = AppHttpService;
@@ -30,6 +30,7 @@ export class ChunkHttpService extends ChunkDataService {
30
30
  }
31
31
 
32
32
 
33
+ //here
33
34
  getMergedChunkForIDList(id, chunkHashesList) {
34
35
 
35
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.2.4-beta.26",
3
+ "version": "1.2.4-beta.28",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {