Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-02 09:17:56 +03:00
parent fce3d8e486
commit 4af852c853

View File

@@ -63,11 +63,15 @@ const productSizeMatchCache = {
rules: [], rules: [],
schemas: {} schemas: {}
} }
const PRODUCT_SIZE_MATCH_TTL_MS = 4 * 60 * 60 * 1000
let productSizeMatchLastFetchAt = 0
let productSizeMatchInflightPromise = null
function resetProductSizeMatchCache() { function resetProductSizeMatchCache() {
productSizeMatchCache.loaded = false productSizeMatchCache.loaded = false
productSizeMatchCache.rules = [] productSizeMatchCache.rules = []
productSizeMatchCache.schemas = {} productSizeMatchCache.schemas = {}
productSizeMatchLastFetchAt = 0
} }
function setProductSizeMatchCache(payload) { function setProductSizeMatchCache(payload) {
@@ -110,6 +114,7 @@ function setProductSizeMatchCache(payload) {
productSizeMatchCache.loaded = true productSizeMatchCache.loaded = true
productSizeMatchCache.rules = normalizedRules productSizeMatchCache.rules = normalizedRules
productSizeMatchCache.schemas = normalizedSchemas productSizeMatchCache.schemas = normalizedSchemas
productSizeMatchLastFetchAt = Date.now()
} }
function buildSchemaMapFromCacheSchemas() { function buildSchemaMapFromCacheSchemas() {
@@ -293,17 +298,31 @@ export const useOrderEntryStore = defineStore('orderentry', {
}, },
async ensureProductSizeMatchRules($q = null, force = false) { 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() this.schemaMap = buildSchemaMapFromCacheSchemas()
return true return true
} }
if (!force && productSizeMatchInflightPromise) {
return productSizeMatchInflightPromise
}
productSizeMatchInflightPromise = (async () => {
try { try {
const res = await api.get('/product-size-match/rules') const res = await api.get('/product-size-match/rules')
setProductSizeMatchCache(res?.data || {}) setProductSizeMatchCache(res?.data || {})
this.schemaMap = buildSchemaMapFromCacheSchemas() this.schemaMap = buildSchemaMapFromCacheSchemas()
return true return true
} catch (err) { } catch (err) {
if (hasCache) {
this.schemaMap = buildSchemaMapFromCacheSchemas()
console.warn('product-size-match refresh failed, using existing cache:', err)
return true
}
if (force) { if (force) {
resetProductSizeMatchCache() resetProductSizeMatchCache()
} }
@@ -314,7 +333,12 @@ export const useOrderEntryStore = defineStore('orderentry', {
message: 'Beden eşleme kuralları alınamadı.' message: 'Beden eşleme kuralları alınamadı.'
}) })
return false return false
} finally {
productSizeMatchInflightPromise = null
} }
})()
return productSizeMatchInflightPromise
}, },