From 648398897a3ee8c761688abfb4b799b8d74121d5 Mon Sep 17 00:00:00 2001 From: pkarw Date: Tue, 23 Apr 2019 17:50:37 +0200 Subject: [PATCH 1/2] Fix to #2729 --- CHANGELOG.md | 1 + config/default.json | 2 +- core/client-entry.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a21040f37c..d1598960ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Global config api path under `api.url` - @BartoszLiburski (#2622) - Google Tag Manager integration - @talalus (#841) - Portuguese (pt-PT) translation - @xlcnd (#2695) +- Added `syncTasks` cleanup, `elasticCacheQuota` lowered to 3096KB - @pkarw (#2729) ### Fixed - Sidebar menu wasn't possible to scroll - @PanMisza (#2627) diff --git a/config/default.json b/config/default.json index 3ebbf6e54c..d8b798c16e 100644 --- a/config/default.json +++ b/config/default.json @@ -14,7 +14,7 @@ "dynamicConfigContinueOnError": false, "dynamicConfigExclude": ["ssr", "storeViews", "entities", "localForage", "shipping", "boost", "query"], "dynamicConfigInclude": [], - "elasticCacheQuota": 4096 + "elasticCacheQuota": 3096 }, "seo": { "useUrlDispatcher": true diff --git a/core/client-entry.ts b/core/client-entry.ts index 6aa7ca76bc..6e520cdfc1 100755 --- a/core/client-entry.ts +++ b/core/client-entry.ts @@ -254,7 +254,7 @@ const invokeClientEntry = async () => { mutex[id] = true // mark this task as being processed fetchQueue.push(() => { return execute(task, currentToken, currentCartId).then(executedTask => { - syncTaskCollection.setItem(executedTask.task_id.toString(), executedTask) + syncTaskCollection.removeItem(executedTask.task_id.toString()) // remove successfully executed task from the queue mutex[id] = false }).catch(err => { mutex[id] = false From 76a75759550ec2b7dd9642eb3b281566c1590dc5 Mon Sep 17 00:00:00 2001 From: pkarw Date: Tue, 23 Apr 2019 18:10:22 +0200 Subject: [PATCH 2/2] Unified initialization of the `syncTasksCollection` --- core/client-entry.ts | 8 ++------ core/lib/sync/index.ts | 8 +------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/core/client-entry.ts b/core/client-entry.ts index 6e520cdfc1..f57408b5c9 100755 --- a/core/client-entry.ts +++ b/core/client-entry.ts @@ -213,11 +213,7 @@ const invokeClientEntry = async () => { // event.data.config - configuration, endpoints etc const storeView = currentStoreView() const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : '' - - const syncTaskCollection = new UniversalStorage(localForage.createInstance({ - name: dbNamePrefix + 'shop', - storeName: 'syncTasks' - })) + const syncTaskCollection = Vue.prototype.$db.syncTaskCollection const usersCollection = new UniversalStorage(localForage.createInstance({ name: (config.storeViews.commonCache ? '' : dbNamePrefix) + 'shop', @@ -254,7 +250,7 @@ const invokeClientEntry = async () => { mutex[id] = true // mark this task as being processed fetchQueue.push(() => { return execute(task, currentToken, currentCartId).then(executedTask => { - syncTaskCollection.removeItem(executedTask.task_id.toString()) // remove successfully executed task from the queue + syncTaskCollection.removeItem(id) // remove successfully executed task from the queue mutex[id] = false }).catch(err => { mutex[id] = false diff --git a/core/lib/sync/index.ts b/core/lib/sync/index.ts index a392501986..cfa5c40a1a 100644 --- a/core/lib/sync/index.ts +++ b/core/lib/sync/index.ts @@ -76,13 +76,7 @@ function execute (task) { // not offline task /** Clear sync tasks that were not transmitted yet */ function clearNotTransmited () { const storeView = currentStoreView() - const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : '' - - const syncTaskCollection = new UniversalStorage(localForage.createInstance({ - name: dbNamePrefix + 'shop', - storeName: 'syncTasks', - driver: localForage[rootStore.state.config.localForage.defaultDrivers['syncTasks']] - })) + const syncTaskCollection = Vue.prototype.$db.syncTaskCollection syncTaskCollection.iterate((task, id, iterationNumber) => { if (!task.transmited) { syncTaskCollection.removeItem(id)