@gudhub/core 1.2.4-beta.3 → 1.2.4-beta.32
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/GUDHUB/AppProcessor/AppProcessor.js +62 -24
- package/GUDHUB/ChunksManager/ChunksManager.js +61 -61
- package/GUDHUB/ChunksManager/ChunksManager.test.js +8 -4
- package/GUDHUB/DataService/AppDataService.js +232 -0
- package/GUDHUB/DataService/ChunkDataService.js +10 -0
- package/GUDHUB/DataService/IndexedDB/IndexedDBAppService.js +799 -63
- package/GUDHUB/DataService/IndexedDB/IndexedDBChunkService.js +303 -46
- package/GUDHUB/DataService/IndexedDB/IndexedDBService.js +342 -2
- package/GUDHUB/DataService/IndexedDB/StoreManager/BaseStoreManager.js +124 -0
- package/GUDHUB/DataService/IndexedDB/StoreManager/managers.js +113 -0
- package/GUDHUB/DataService/IndexedDB/appDataConf.js +6 -3
- package/GUDHUB/DataService/IndexedDB/appRequestWorker.js +225 -0
- package/GUDHUB/DataService/IndexedDB/chunkDataConf.js +3 -3
- package/GUDHUB/DataService/IndexedDB/consts.js +3 -1
- package/GUDHUB/DataService/IndexedDB/init.js +15 -14
- package/GUDHUB/DataService/IndexedDB/storeManagerConf/chunkCacheStoreManagerConf.js +11 -0
- package/GUDHUB/DataService/IndexedDB/storeManagerConf/init.js +1 -0
- package/GUDHUB/DataService/export.js +8 -5
- package/GUDHUB/DataService/httpService/AppHttpService.js +22 -4
- package/GUDHUB/DataService/httpService/ChunkHttpService.js +19 -2
- package/GUDHUB/DataService/utils.js +104 -1
- package/GUDHUB/FileManager/FileManager.js +7 -3
- package/GUDHUB/GHConstructor/createAngularModuleInstance.js +3 -3
- package/GUDHUB/GHConstructor/createClassInstance.js +3 -3
- package/GUDHUB/ItemProcessor/ItemProcessor.js +24 -0
- package/GUDHUB/Storage/ModulesList.js +18 -2
- package/GUDHUB/Utils/AppsTemplateService/AppsTemplateService.js +37 -1
- package/GUDHUB/Utils/Utils.js +29 -1
- package/GUDHUB/Utils/merge_chunks/merge_chunks.js +36 -28
- package/GUDHUB/Utils/merge_chunks/merge_chunks.worker.js +78 -0
- package/GUDHUB/Utils/merge_compare_items/merge_compare_items.js +40 -9
- package/GUDHUB/WebSocket/WebSocket.js +2 -1
- package/GUDHUB/consts.js +21 -1
- package/GUDHUB/gudhub.js +39 -14
- package/appRequestWorker.js +1 -0
- package/appRequestWorker.js.LICENSE.txt +13 -0
- package/appRequestWorker.js.map +1 -0
- package/package.json +17 -6
- package/umd/appRequestWorker.js +1 -0
- package/umd/library.min.js +1 -300
- package/webpack.config.js +154 -0
- package/.vscode/launch.json +0 -31
- package/umd/library.min.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IS_WEB } from "../consts.js";
|
|
1
|
+
import { IS_BROWSER, IS_BROWSER_MAIN_THREAD, IS_WEB } from "../consts.js";
|
|
2
2
|
|
|
3
3
|
export class AppProcessor {
|
|
4
4
|
constructor(
|
|
@@ -6,7 +6,7 @@ export class AppProcessor {
|
|
|
6
6
|
pipeService,
|
|
7
7
|
req,
|
|
8
8
|
websocket,
|
|
9
|
-
chunksManager,
|
|
9
|
+
// chunksManager,
|
|
10
10
|
util,
|
|
11
11
|
activateSW,
|
|
12
12
|
dataService,
|
|
@@ -17,10 +17,15 @@ export class AppProcessor {
|
|
|
17
17
|
this.ws = websocket;
|
|
18
18
|
this.applistReceived = false;
|
|
19
19
|
this.activateSW = activateSW; // we use this flag to check if applist was received. The problem is that if you receive an app it also goes to app_list as a result you have the app_list with one app.
|
|
20
|
-
this.chunksManager = chunksManager;
|
|
20
|
+
// this.chunksManager = chunksManager;
|
|
21
21
|
this.util = util;
|
|
22
22
|
this.appListeners();
|
|
23
23
|
this.dataService = dataService;
|
|
24
|
+
|
|
25
|
+
this.appRequestCache = new Map;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// this.dataServiceRequestedIdSet = new Set;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
async createNewAppApi(app) {
|
|
@@ -230,7 +235,7 @@ export class AppProcessor {
|
|
|
230
235
|
// Here we get default user's app
|
|
231
236
|
// We do it here to do it only once
|
|
232
237
|
// We do it because we need to initialize WebSockets, which we do in getApp method
|
|
233
|
-
this.getApp(this.storage.getUser().app_init);
|
|
238
|
+
// this.getApp(this.storage.getUser().app_init); // commented due to unfinished app_init development, its shape causes exceptions
|
|
234
239
|
}
|
|
235
240
|
|
|
236
241
|
return app_list;
|
|
@@ -255,27 +260,48 @@ export class AppProcessor {
|
|
|
255
260
|
let app = this.getAppFromStorage(app_id);
|
|
256
261
|
if (app) return app;
|
|
257
262
|
|
|
258
|
-
|
|
259
|
-
if (!receivedApp) return;
|
|
263
|
+
if (this.appRequestCache.has(app_id)) return this.appRequestCache.get(app_id);
|
|
260
264
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
265
|
+
let self = this;
|
|
266
|
+
|
|
267
|
+
let pr = new Promise(async (resolve, reject) => {
|
|
268
|
+
try {
|
|
269
|
+
let app = await self.dataService.getApp(app_id);
|
|
270
|
+
if (!app) reject();
|
|
271
|
+
|
|
272
|
+
//!!! temporary check !!!! if app has chanks property then we start getting it
|
|
273
|
+
// if (
|
|
274
|
+
// receivedApp.chunks &&
|
|
275
|
+
// receivedApp.chunks.length
|
|
276
|
+
// ) {
|
|
277
|
+
// // here should be checked is merge required
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
// let chunks = await self.chunksManager.getChunks(app_id, receivedApp.chunks);
|
|
281
|
+
// receivedApp.items_list = self.util.mergeChunks([
|
|
282
|
+
// ...chunks,
|
|
283
|
+
// receivedApp,
|
|
284
|
+
// ]);
|
|
285
|
+
// }
|
|
272
286
|
|
|
273
|
-
this.saveAppInStorage(receivedApp);
|
|
274
|
-
this.ws.addSubscription(app_id);
|
|
275
287
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
288
|
+
// This code for trash must be changed
|
|
289
|
+
// return trash ? app : {...app, items_list: app.items_list.filter(item => !item.trash)};
|
|
290
|
+
let filtered = trash ? app : {...app, items_list: app.items_list.filter(item => !item.trash)};
|
|
291
|
+
filtered = trash ? filtered : {...filtered, field_list: filtered.field_list.filter(f => !f.trash)};
|
|
292
|
+
|
|
293
|
+
resolve(filtered);
|
|
294
|
+
|
|
295
|
+
self.saveAppInStorage(filtered);
|
|
296
|
+
self.ws.addSubscription(app_id);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
reject();
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
self.appRequestCache.set(app_id, pr);
|
|
303
|
+
|
|
304
|
+
return pr;
|
|
279
305
|
}
|
|
280
306
|
|
|
281
307
|
async updateApp(app) {
|
|
@@ -319,6 +345,18 @@ export class AppProcessor {
|
|
|
319
345
|
}
|
|
320
346
|
}
|
|
321
347
|
|
|
348
|
+
async handleAppChange(id, prevVersion, nextVersion) {
|
|
349
|
+
let res1 = this.util.areViewListsEqual(prevVersion.views_list, nextVersion.views_list);
|
|
350
|
+
let res2 = this.util.areFieldListsEqual(prevVersion.field_list, nextVersion.field_list);
|
|
351
|
+
|
|
352
|
+
if (
|
|
353
|
+
res1 ||
|
|
354
|
+
res2
|
|
355
|
+
) {
|
|
356
|
+
this.updateAppFieldsAndViews({id, views_list: nextVersion.views_list, field_list: nextVersion.field_list});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
322
360
|
clearAppProcessor() {
|
|
323
361
|
this.getAppListPromises = null;
|
|
324
362
|
this.getAppPromises = {};
|
|
@@ -415,7 +453,7 @@ export class AppProcessor {
|
|
|
415
453
|
appsList
|
|
416
454
|
);
|
|
417
455
|
});
|
|
418
|
-
if (
|
|
456
|
+
if (IS_BROWSER_MAIN_THREAD && this.activateSW) {
|
|
419
457
|
navigator.serviceWorker.addEventListener("message", async (event) => {
|
|
420
458
|
if (event.data.type === "refresh app") {
|
|
421
459
|
const app = await this.getApp(event.data.payload.app_id);
|
|
@@ -457,7 +495,7 @@ export class AppProcessor {
|
|
|
457
495
|
}
|
|
458
496
|
);
|
|
459
497
|
}
|
|
460
|
-
event.data.payload.items_list = this.util.mergeChunks([app, event.data.payload])
|
|
498
|
+
event.data.payload.items_list = await this.util.mergeChunks([app, event.data.payload]) //here check Ask Andrew
|
|
461
499
|
this.saveAppInStorage(event.data.payload);
|
|
462
500
|
}
|
|
463
501
|
// if (event.data.type === "refresh appList") {
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { ChunkAPI } from "../api/ChunkApi.js";
|
|
1
|
+
// import { ChunkAPI } from "../api/ChunkApi.js";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
export class ChunksManager {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
// export class ChunksManager {
|
|
5
|
+
// constructor(
|
|
6
|
+
// storage,
|
|
7
|
+
// pipeService,
|
|
8
|
+
// req,
|
|
9
|
+
// util,
|
|
10
|
+
// dataService,
|
|
11
|
+
// ) {
|
|
12
|
+
// this.storage = storage;
|
|
13
|
+
// this.pipeService = pipeService;
|
|
14
|
+
// this.req = req;
|
|
15
|
+
// this.util = util;
|
|
16
|
+
// this.dataService = dataService;
|
|
17
|
+
// this.chunkApi = new ChunkAPI(req);
|
|
18
|
+
// this.itemListeners();
|
|
19
|
+
// }
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
// async getChunk(app_id, chunk_id) {
|
|
22
|
+
// try {
|
|
23
|
+
// return this.dataService.getChunk(app_id, chunk_id);
|
|
24
|
+
// } catch (err) {
|
|
25
|
+
// console.log(err);
|
|
26
|
+
// return null;
|
|
27
|
+
// }
|
|
28
|
+
// }
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
// async getLastChunk(app_id) {
|
|
31
|
+
// try {
|
|
32
|
+
// return this.chunkApi.getLastChunk(app_id);
|
|
33
|
+
// } catch (err) {
|
|
34
|
+
// console.log(err);
|
|
35
|
+
// return null;
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
// async getChunks(app_id, chunk_ids) {
|
|
40
|
+
// let chunks = [];
|
|
41
|
+
// if(chunk_ids){
|
|
42
|
+
// chunks = await Promise.all(chunk_ids.map((chunk_id) => this.getChunk(app_id, chunk_id)));
|
|
43
|
+
// }
|
|
44
|
+
// return chunks;
|
|
45
|
+
// }
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
// itemListeners() {
|
|
48
|
+
// }
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
50
|
+
// async getApp(app_id) {
|
|
51
|
+
// if (!app_id) return null;
|
|
52
|
+
// let app = this.getAppFromStorage(app_id);
|
|
53
|
+
// if (!app) {
|
|
54
|
+
// if (this.getAppPromises[app_id]) {
|
|
55
|
+
// return this.getAppPromises[app_id];
|
|
56
|
+
// }
|
|
57
|
+
// this.getAppPromises[app_id] = this.getAppApi(app_id);
|
|
58
|
+
// app = await this.getAppPromises[app_id];
|
|
59
|
+
// if (app) {
|
|
60
|
+
// this.saveAppInStorage(app);
|
|
61
|
+
// this.ws.addSubscription(app_id);
|
|
62
|
+
// } else {
|
|
63
|
+
// return null;
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
// return app;
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import should from "should";
|
|
2
2
|
import {GudHub} from './../gudhub.js';
|
|
3
|
+
import { ChunkDataService } from "../DataService/export.js";
|
|
3
4
|
|
|
4
5
|
describe("CHUNKS MANAGER", async function() {
|
|
5
6
|
const auth_key = 'Z/lxMHLenEaQTvPjW5U6c3jBDwWFYZrh2F9Kxa3fbt8drvabS2u2lXQ2zI+SRmic';
|
|
@@ -9,7 +10,10 @@ describe("CHUNKS MANAGER", async function() {
|
|
|
9
10
|
it("GET CHUNK : here we get first chunk from App", async function () {
|
|
10
11
|
this.timeout(10000);
|
|
11
12
|
var app = await gudhub.getApp(8263);
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
let chunkDataService = new ChunkDataService(); //TODO args
|
|
15
|
+
|
|
16
|
+
let firstChunk = await gudhub.chunksManager.getChunk(8263, app.chunks[0]);// getapp - get firstChunk from it and then load via service or via api, maybe create here chunkDataService instance
|
|
13
17
|
firstChunk.should.have.property("chunk_number");
|
|
14
18
|
firstChunk.should.have.property("items_list");
|
|
15
19
|
firstChunk.items_list[0].fields[0].should.have.property("history");
|
|
@@ -18,7 +22,7 @@ describe("CHUNKS MANAGER", async function() {
|
|
|
18
22
|
|
|
19
23
|
it("GET LAST CHUNK : here we should get last chunk", async function () {
|
|
20
24
|
this.timeout(5000);
|
|
21
|
-
let firstChunk = await gudhub.chunksManager.getLastChunk(8263)
|
|
25
|
+
let firstChunk = await gudhub.chunksManager.getLastChunk(8263);//
|
|
22
26
|
|
|
23
27
|
firstChunk.should.have.property("chunk_number");
|
|
24
28
|
firstChunk.should.have.property("items_list");
|
|
@@ -27,7 +31,7 @@ describe("CHUNKS MANAGER", async function() {
|
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
it("GET CHUNKS : here we getting chanks from empty array []", async function () {
|
|
30
|
-
let chunkedItems = await gudhub.chunksManager.getChunks(8263, [])
|
|
34
|
+
let chunkedItems = await gudhub.chunksManager.getChunks(8263, []);//
|
|
31
35
|
chunkedItems.length.should.equal(0);
|
|
32
36
|
});
|
|
33
37
|
|
|
@@ -35,7 +39,7 @@ describe("CHUNKS MANAGER", async function() {
|
|
|
35
39
|
it("GET CHUNKS : here we should receive all chunks of app", async function () {
|
|
36
40
|
this.timeout(1000000);
|
|
37
41
|
var app = await gudhub.getApp(8263);
|
|
38
|
-
let chunkedItems = await gudhub.chunksManager.getChunks(8263, app.chunks)
|
|
42
|
+
let chunkedItems = await gudhub.chunksManager.getChunks(8263, app.chunks);//
|
|
39
43
|
|
|
40
44
|
chunkedItems[0].items_list[0].should.have.property("fields");
|
|
41
45
|
chunkedItems[0].items_list[0].should.have.property("item_id");
|
|
@@ -1,5 +1,237 @@
|
|
|
1
1
|
import { DataService } from "./DataService.js";
|
|
2
|
+
import { ChunkDataService, chunkDataServiceConf } from "./export.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
//TODO processRequestedApp should be checked that all code is ok !!!!!!!!!!!!!!!! Ive not ended checking
|
|
2
7
|
|
|
3
8
|
export class AppDataService extends DataService {
|
|
4
9
|
//interface for indexeddb and http services
|
|
10
|
+
|
|
11
|
+
constructor(req, conf, gudhub) {
|
|
12
|
+
super();
|
|
13
|
+
this.chunkDataService = new ChunkDataService(req, chunkDataServiceConf, gudhub);
|
|
14
|
+
this.gudhub = gudhub;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
isWithCache() {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
//here
|
|
24
|
+
async processRequestedApp(id, sentData) {
|
|
25
|
+
|
|
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
|
+
|
|
44
|
+
|
|
45
|
+
// all implementations are without cache for now
|
|
46
|
+
if (
|
|
47
|
+
!this.isWithCache()
|
|
48
|
+
) {
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// let resultedMergedChunks = this.chunkDataService.getMergedChunk(id, sentData.chunks);
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
///TODO here chunks could be with cache too
|
|
55
|
+
|
|
56
|
+
// async getChunks(app_id, chunk_ids) {
|
|
57
|
+
// let chunks = [];
|
|
58
|
+
// if(chunk_ids){
|
|
59
|
+
// chunks = await Promise.all(chunk_ids.map((chunk_id) => this.getChunk(app_id, chunk_id)));
|
|
60
|
+
// }
|
|
61
|
+
// return chunks;
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
// let res = await this.chunkDataService.getChunks(id, sentData.chunks);
|
|
65
|
+
// let res = await Promise.all(sentData.chunks.map((chunk_id) => this.chunkDataService.getChunk(id, chunk_id)));
|
|
66
|
+
|
|
67
|
+
let res = await this.chunkDataService.getMergedChunkForIDList(id, sentData.chunks);
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if (
|
|
71
|
+
res
|
|
72
|
+
) {
|
|
73
|
+
sentData.items_list = await this.gudhub.util.mergeChunks([
|
|
74
|
+
res,
|
|
75
|
+
sentData,
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// if (!res) res = [];
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
//TODO should be in new thread too even for Node.js becauses this will block loop
|
|
84
|
+
|
|
85
|
+
// sentData.items_list = await this.gudhub.util.mergeChunks([
|
|
86
|
+
// ...res,
|
|
87
|
+
// sentData,
|
|
88
|
+
// ]);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
return sentData;
|
|
92
|
+
|
|
93
|
+
// this.dataService.putApp(id, nextVersion);
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
// return this.mergeAndReturnStrategy.handle(sentData, chunks);
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
throw new Error;
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
|
|
113
|
+
// я там собираюсь склеивать все данные в этом методе, надо посмотреть не будет ли проблем для ноды итп там тоже process вызывается
|
|
114
|
+
let cachedApp = await this.getCached(id); // this should be merged chunk + app from db
|
|
115
|
+
|
|
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
|
+
|
|
128
|
+
// let cachedMergedChunk = await this.chunkDataService.getCachedMergedChunk(id, cachedApp.chunks);
|
|
129
|
+
|
|
130
|
+
if (
|
|
131
|
+
!cachedApp
|
|
132
|
+
// cachedMergedChunk ?
|
|
133
|
+
) {
|
|
134
|
+
|
|
135
|
+
//TODO maybe dont wait for chunks at first load
|
|
136
|
+
|
|
137
|
+
// let res = await this.chunkDataService.getChunks(id, sentData.chunks);
|
|
138
|
+
// let res = await Promise.all(sentData.chunks.map((chunk_id) => this.chunkDataService.getChunk(id, chunk_id)));
|
|
139
|
+
let res = await this.chunkDataService.getMergedChunkForIDList(id, sentData.chunks);
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
if (
|
|
143
|
+
res
|
|
144
|
+
) {
|
|
145
|
+
sentData.items_list = await this.gudhub.util.mergeChunks([
|
|
146
|
+
res,
|
|
147
|
+
sentData,
|
|
148
|
+
]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// this.putInCache(id, sentData);
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
return sentData;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
// let newHashesList = sentData.chunks.filter(c => !cachedApp.chunks.includes(c));
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
// let self = this;
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
// let res = await this.chunkDataService.getChunks(id, newHashesList);
|
|
165
|
+
// let res = await Promise.all(newHashesList.map((chunk_id) => this.chunkDataService.getChunk(id, chunk_id)));
|
|
166
|
+
|
|
167
|
+
let res = await this.chunkDataService.getCachedMergedChunk(id, cachedApp.chunks);
|
|
168
|
+
|
|
169
|
+
// if (!res) res = [];
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
if (
|
|
174
|
+
res
|
|
175
|
+
) {
|
|
176
|
+
sentData.items_list = await this.gudhub.util.mergeChunks([
|
|
177
|
+
cachedApp,
|
|
178
|
+
res,
|
|
179
|
+
sentData,
|
|
180
|
+
]);
|
|
181
|
+
} else {
|
|
182
|
+
sentData.items_list = await this.gudhub.util.mergeChunks([
|
|
183
|
+
cachedApp,
|
|
184
|
+
sentData,
|
|
185
|
+
]);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
// this.chunkDataService.getChunks(id, newHashesList).then((res) => {
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
//TODO check this for AppHttpService, seems isnt necessary
|
|
198
|
+
// this.gudhub.triggerAppChange(id, cachedVersion, sentData);
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
// self.putInCache(id, sentData);
|
|
202
|
+
// });
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
return sentData;
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
// return cachedVersion;
|
|
210
|
+
|
|
211
|
+
} catch (error) {
|
|
212
|
+
|
|
213
|
+
// seems try catch here isnt handling almost anything, almost identical code here
|
|
214
|
+
|
|
215
|
+
// res = await this.chunkDataService.getChunks(id, sentData.chunks);
|
|
216
|
+
// let res = await Promise.all(sentData.chunks.map((chunk_id) => this.chunkDataService.getChunk(id, chunk_id)));
|
|
217
|
+
let res = await this.chunkDataService.getMergedChunkForIDList(sentData.chunks);
|
|
218
|
+
|
|
219
|
+
// if (!res) res = [];
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
if (
|
|
223
|
+
res
|
|
224
|
+
) {
|
|
225
|
+
sentData.items_list = await this.gudhub.util.mergeChunks([
|
|
226
|
+
res,
|
|
227
|
+
sentData,
|
|
228
|
+
]);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// this.putInCache(id, sentData);
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
return sentData;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
5
237
|
}
|