Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -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
|
||||
},
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user