Fix product performance grouped JSON build
This commit is contained in:
@@ -26,13 +26,6 @@ function resolveProductImageUrls (item) {
|
||||
if (url && !urls.includes(url)) urls.push(url)
|
||||
}
|
||||
|
||||
const contentURL = String(item.content_url || item.ContentURL || '').trim()
|
||||
if (contentURL.startsWith('/api/')) addURL(contentURL)
|
||||
else if (contentURL.startsWith('/')) addURL(`/api${contentURL}`)
|
||||
|
||||
const imageId = Number(item.id || item.ID || 0)
|
||||
if (Number.isFinite(imageId) && imageId > 0) addURL(`/api/product-images/${imageId}/content`)
|
||||
|
||||
const thumbURL = String(item.thumb_url || item.thumbUrl || '').trim()
|
||||
addURL(thumbURL)
|
||||
|
||||
@@ -44,6 +37,13 @@ function resolveProductImageUrls (item) {
|
||||
|
||||
const fileName = String(item.file_name || item.FileName || '').trim()
|
||||
if (fileName) addURL(`/uploads/image/${fileName}`)
|
||||
|
||||
const contentURL = String(item.content_url || item.ContentURL || '').trim()
|
||||
if (contentURL.startsWith('/api/')) addURL(contentURL)
|
||||
else if (contentURL.startsWith('/')) addURL(`/api${contentURL}`)
|
||||
|
||||
const imageId = Number(item.id || item.ID || 0)
|
||||
if (Number.isFinite(imageId) && imageId > 0) addURL(`/api/product-images/${imageId}/content`)
|
||||
return urls
|
||||
}
|
||||
|
||||
@@ -69,6 +69,9 @@ export const useProductPerformanceStore = defineStore('product-performance-store
|
||||
groupedLoadedAtByKey: {},
|
||||
groupedLoadingByKey: {},
|
||||
groupedInFlightByKey: {},
|
||||
groupedFilterOptionsByKey: {},
|
||||
groupedFilterOptionsLoadedAtByKey: {},
|
||||
groupedFilterOptionsInFlightByKey: {},
|
||||
imageUrlByKey: {},
|
||||
imageListByKey: {},
|
||||
imageLoadedAtByKey: {}
|
||||
@@ -96,6 +99,16 @@ export const useProductPerformanceStore = defineStore('product-performance-store
|
||||
})
|
||||
},
|
||||
|
||||
groupedFilterOptionsCacheKey (params = {}) {
|
||||
return JSON.stringify({
|
||||
mode: String(params.mode || ''),
|
||||
mainGroup: String(params.urunAnaGrubu || params.urun_ana_grubu || ''),
|
||||
groupLevels: normalizedList(params.groupLevels),
|
||||
fields: normalizedList(params.fields, true),
|
||||
limit: Number(params.limit || 0)
|
||||
})
|
||||
},
|
||||
|
||||
async fetchGroupedRows (params = {}, options = {}) {
|
||||
const key = this.groupedCacheKey(params)
|
||||
const now = Date.now()
|
||||
@@ -180,6 +193,35 @@ export const useProductPerformanceStore = defineStore('product-performance-store
|
||||
return request
|
||||
},
|
||||
|
||||
async fetchGroupedFilterOptions (params = {}, options = {}) {
|
||||
const key = this.groupedFilterOptionsCacheKey(params)
|
||||
const now = Date.now()
|
||||
const loadedAt = Number(this.groupedFilterOptionsLoadedAtByKey[key] || 0)
|
||||
const cached = this.groupedFilterOptionsByKey[key]
|
||||
if (!options.force && cached && now - loadedAt < GROUPED_TTL_MS) return cached
|
||||
if (this.groupedFilterOptionsInFlightByKey[key]) return this.groupedFilterOptionsInFlightByKey[key]
|
||||
|
||||
const request = api.post('/pricing/product-performance/grouped/filter-options', {
|
||||
mode: params.mode,
|
||||
urun_ana_grubu: params.urunAnaGrubu || params.urun_ana_grubu || '',
|
||||
group_levels: Array.isArray(params.groupLevels) ? params.groupLevels : String(params.groupLevels || '').split(',').filter(Boolean),
|
||||
fields: Array.isArray(params.fields) ? params.fields : String(params.fields || '').split(',').filter(Boolean),
|
||||
limit: params.limit || 5000
|
||||
}, { timeout: 60000 }).then(resp => {
|
||||
const data = resp?.data && typeof resp.data === 'object' ? resp.data : {}
|
||||
this.groupedFilterOptionsByKey = { ...this.groupedFilterOptionsByKey, [key]: data }
|
||||
this.groupedFilterOptionsLoadedAtByKey = { ...this.groupedFilterOptionsLoadedAtByKey, [key]: Date.now() }
|
||||
return data
|
||||
}).finally(() => {
|
||||
const nextInFlight = { ...this.groupedFilterOptionsInFlightByKey }
|
||||
delete nextInFlight[key]
|
||||
this.groupedFilterOptionsInFlightByKey = nextInFlight
|
||||
})
|
||||
|
||||
this.groupedFilterOptionsInFlightByKey = { ...this.groupedFilterOptionsInFlightByKey, [key]: request }
|
||||
return request
|
||||
},
|
||||
|
||||
setImageCache (key, urls = []) {
|
||||
const normalizedKey = String(key || '').trim()
|
||||
if (!normalizedKey) return
|
||||
|
||||
Reference in New Issue
Block a user