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: [],
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
},