diff --git a/CHANGELOG.md b/CHANGELOG.md index d771bbf13c..e116381481 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moves theme specific stores and components into themes - @michasik (#3139) - Decreased the `localStorage` quota usage + error handling by introducing new config variables: `config.products.disablePersistentProductsCache` to not store products by SKU (by default it's on). Products are cached in ServiceWorker cache anyway so the `product/list` will populate the in-memory cache (`cache.setItem(..., memoryOnly = true)`); `config.seo.disableUrlRoutesPersistentCache` - to not store the url mappings; they're stored in in-memory cache anyway so no additional requests will be made to the backend for url mapping; however it might cause some issues with url routing in the offline mode (when the offline mode PWA installed on homescreen got reloaded, the in-memory cache will be cleared so there won't potentially be the url mappings; however the same like with `product/list` the ServiceWorker cache SHOULD populate url mappings anyway); `config.syncTasks.disablePersistentTaskQueue` to not store the network requests queue in service worker. Currently only the stock-check and user-data changes were using this queue. The only downside it introuces can be related to the offline mode and these tasks will not be re-executed after connectivity established, but just in a case when the page got reloaded while offline (yeah it might happen using ServiceWorker; `syncTasks` can't be re-populated in cache from SW) - @pkarw (#3180) - Translation file improvements - @vishal-7037 (#3198) +- Added configuration for max attempt task & cart by pass - @cnviradiya (#3193) ## [1.10.0-rc.2] - UNRELEASED diff --git a/config/default.json b/config/default.json index 29ed75bac6..8b5f9acfe5 100644 --- a/config/default.json +++ b/config/default.json @@ -87,6 +87,10 @@ "initialStateFilter": ["__DEMO_MODE__", "version", "storeView"], "useInitialStateFilter": true }, + "queues": { + "maxNetworkTaskAttempts": 1, + "maxCartBypassAttempts": 1 + }, "defaultStoreCode": "", "storeViews": { "multistore": false, diff --git a/core/lib/sync/task.ts b/core/lib/sync/task.ts index 5ba0b41c7e..a83924681f 100644 --- a/core/lib/sync/task.ts +++ b/core/lib/sync/task.ts @@ -17,7 +17,6 @@ import { serial } from '@vue-storefront/core/helpers' import config from 'config' import { onlineHelper } from '@vue-storefront/core/helpers' -const AUTO_REFRESH_MAX_ATTEMPTS = 20 export function _prepareTask (task) { const taskId = entities.uniqueEntityId(task) // timestamp as a order id is not the best we can do but it's enough @@ -84,7 +83,7 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar if (config.users.autoRefreshTokens) { if (!rootStore.state.userTokenInvalidateLock) { rootStore.state.userTokenInvalidateLock++ - if (rootStore.state.userTokenInvalidateAttemptsCount >= AUTO_REFRESH_MAX_ATTEMPTS) { + if (rootStore.state.userTokenInvalidateAttemptsCount >= config.queues.maxNetworkTaskAttempts) { Logger.error('Internal Application error while refreshing the tokens. Please clear the storage and refresh page.', 'sync')() rootStore.state.userTokenInvalidateLock = -1 rootStore.dispatch('user/logout', { silent: true }) @@ -120,7 +119,7 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar }) } } - if (rootStore.state.userTokenInvalidateAttemptsCount <= AUTO_REFRESH_MAX_ATTEMPTS) _internalExecute(resolve, reject, task, currentToken, currentCartId) // retry + if (rootStore.state.userTokenInvalidateAttemptsCount <= config.queues.maxNetworkTaskAttempts) _internalExecute(resolve, reject, task, currentToken, currentCartId) // retry } else { Logger.info('Invalidation process is disabled (autoRefreshTokens is set to false)', 'sync')() rootStore.dispatch('user/logout', { silent: true }) diff --git a/core/modules/cart/store/actions.ts b/core/modules/cart/store/actions.ts index 31845e321d..368336740c 100644 --- a/core/modules/cart/store/actions.ts +++ b/core/modules/cart/store/actions.ts @@ -16,7 +16,6 @@ import { isServer } from '@vue-storefront/core/helpers' import config from 'config' import Task from '@vue-storefront/core/lib/sync/types/Task' -const MAX_BYPASS_COUNT = 10 let _connectBypassCount = 0 function _getDifflogPrototype () { @@ -207,7 +206,7 @@ const actions: ActionTree = { diffLog = await dispatch('merge', { serverItems: task.result, clientItems: getters.getCartItems, dryRun: dryRun, forceClientState: forceClientState }) } else { Logger.error(task.result, 'cart') // override with guest cart() - if (_connectBypassCount < MAX_BYPASS_COUNT) { + if (_connectBypassCount < config.queues.maxCartBypassAttempts) { Logger.log('Bypassing with guest cart' + _connectBypassCount, 'cart')() _connectBypassCount = _connectBypassCount + 1 await dispatch('connect', { guestCart: true }) @@ -524,7 +523,7 @@ const actions: ActionTree = { } else { let resultString = task.result ? toString(task.result) : null if (resultString && (resultString.indexOf(i18n.t('not authorized')) < 0 && resultString.indexOf('not authorized')) < 0) { // not respond to unathorized errors here - if (_connectBypassCount < MAX_BYPASS_COUNT) { + if (_connectBypassCount < config.queues.maxCartBypassAttempts) { Logger.log('Bypassing with guest cart' + _connectBypassCount, 'cart')() _connectBypassCount = _connectBypassCount + 1 Logger.error(task.result, 'cart')() diff --git a/docs/guide/basics/configuration.md b/docs/guide/basics/configuration.md index a9af776938..5093753e92 100644 --- a/docs/guide/basics/configuration.md +++ b/docs/guide/basics/configuration.md @@ -94,6 +94,21 @@ The SSR data is being completed in the `asyncData` static method. If this config If it's set to `false`, then **just the** `src/themes/default/pages/Product.vue` -> `asyncData` will be executed. This option is referenced in the [core/client-entry.ts](https://github.com/DivanteLtd/vue-storefront/blob/master/core/client-entry.ts) line: 85. +## Max attempt of tasks + +```json +"queues": { + "maxNetworkTaskAttempts": 1, + "maxCartBypassAttempts": 1 +}, +``` + +This both option is used when you don't want re-attempting task of just X number time attempt task. + +`maxNetworkTaskAttempts` config variable is referenced in the [core/lib/sync/task.ts](https://github.com/DivanteLtd/vue-storefront/blob/master/core/lib/sync/task.ts) and It's reattempt if user token is invalid. + +`maxCartBypassAttempts` config variable is referenced in the [core/modules/cart/store/actions.ts](https://github.com/DivanteLtd/vue-storefront/blob/master/core/modules/cart/store/actions.ts) + ## Default store code ```json