From 4af852c85312aa0f342a4dad4f9a299eb1310715 Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Thu, 2 Apr 2026 09:17:56 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ui/src/stores/orderentryStore.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/ui/src/stores/orderentryStore.js b/ui/src/stores/orderentryStore.js index dcc34d3..fa5ff99 100644 --- a/ui/src/stores/orderentryStore.js +++ b/ui/src/stores/orderentryStore.js @@ -63,11 +63,15 @@ const productSizeMatchCache = { rules: [], schemas: {} } +const PRODUCT_SIZE_MATCH_TTL_MS = 4 * 60 * 60 * 1000 +let productSizeMatchLastFetchAt = 0 +let productSizeMatchInflightPromise = null function resetProductSizeMatchCache() { productSizeMatchCache.loaded = false productSizeMatchCache.rules = [] productSizeMatchCache.schemas = {} + productSizeMatchLastFetchAt = 0 } function setProductSizeMatchCache(payload) { @@ -110,6 +114,7 @@ function setProductSizeMatchCache(payload) { productSizeMatchCache.loaded = true productSizeMatchCache.rules = normalizedRules productSizeMatchCache.schemas = normalizedSchemas + productSizeMatchLastFetchAt = Date.now() } function buildSchemaMapFromCacheSchemas() { @@ -293,17 +298,31 @@ export const useOrderEntryStore = defineStore('orderentry', { }, async ensureProductSizeMatchRules($q = null, force = false) { - if (!force && productSizeMatchCache.loaded && productSizeMatchCache.rules.length > 0) { + const hasCache = productSizeMatchCache.loaded && productSizeMatchCache.rules.length > 0 + const cacheAge = hasCache ? (Date.now() - productSizeMatchLastFetchAt) : Number.POSITIVE_INFINITY + const isFresh = hasCache && cacheAge < PRODUCT_SIZE_MATCH_TTL_MS + + if (!force && isFresh) { this.schemaMap = buildSchemaMapFromCacheSchemas() return true } - try { + if (!force && productSizeMatchInflightPromise) { + return productSizeMatchInflightPromise + } + + productSizeMatchInflightPromise = (async () => { + try { const res = await api.get('/product-size-match/rules') setProductSizeMatchCache(res?.data || {}) this.schemaMap = buildSchemaMapFromCacheSchemas() return true } catch (err) { + if (hasCache) { + this.schemaMap = buildSchemaMapFromCacheSchemas() + console.warn('product-size-match refresh failed, using existing cache:', err) + return true + } if (force) { resetProductSizeMatchCache() } @@ -314,7 +333,12 @@ export const useOrderEntryStore = defineStore('orderentry', { message: 'Beden eşleme kuralları alınamadı.' }) return false + } finally { + productSizeMatchInflightPromise = null } + })() + + return productSizeMatchInflightPromise },