Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-06-18 17:31:53 +03:00
parent f8c0fe338a
commit 149cea778e
8 changed files with 505 additions and 7 deletions

View File

@@ -2441,7 +2441,9 @@ function scheduleReload () {
async function fetchChunk ({ page = 1, useCache = true } = {}) {
const filters = buildServerFilters()
const hasAnyFilter = Object.values(filters).some((v) => Array.isArray(v) && v.length > 0)
const productCodeCount = Array.isArray(filters.product_code) ? filters.product_code.length : 0
const hasPrimaryFilter = (filters.urun_ilk_grubu?.length || 0) > 0 || (filters.urun_ana_grubu?.length || 0) > 0
const hasNarrowProductFilter = productCodeCount > 0
if (!hasAnyFilter) {
// This endpoint is expensive without filters; require the user to scope down first.
store.rows = []
@@ -2452,7 +2454,7 @@ async function fetchChunk ({ page = 1, useCache = true } = {}) {
store.hasMore = false
return 0
}
if (!hasPrimaryFilter) {
if (!hasPrimaryFilter && !hasNarrowProductFilter) {
store.rows = []
store.error = GUIDANCE_MSG
store.totalCount = 0
@@ -2461,8 +2463,11 @@ async function fetchChunk ({ page = 1, useCache = true } = {}) {
store.hasMore = false
return 0
}
const effectiveLimit = hasNarrowProductFilter
? Math.max(productCodeCount, 1)
: PAGE_LIMIT
const result = await store.fetchRows({
limit: PAGE_LIMIT,
limit: effectiveLimit,
page,
append: false,
silent: false,

View File

@@ -869,6 +869,8 @@ const PAGE_LIMIT = 50
const currentPage = ref(1)
let reloadTimer = null
const variantRows = ref([])
const variantRowsCache = new Map()
const VARIANT_ROWS_CACHE_LIMIT = 16
const GUIDANCE_MSG = "Calismak icin once Urun Ilk Grubu veya Urun Ana Grubu Secin ve GRUPLARI GETIR'e Basin."
@@ -2145,6 +2147,7 @@ async function calculateRow (row) {
})
Notify.create({ type: 'positive', message: 'Secilen kayitlar silindi.' })
selectedCampaignHistoryIds.value = []
clearVariantRowsCache()
await reloadCampaignHistory()
await reloadData({ page: currentPage.value, useCache: false })
}
@@ -2314,6 +2317,7 @@ async function saveSelectedRows () {
// This avoids "Kaydet(1) but checkbox not ticked" confusion and ensures UI reflects DB.
selectedMap.value = {}
showSelectedOnly.value = false
clearVariantRowsCache()
await reloadData({ page: currentPage.value, useCache: false })
} catch (err) {
console.error('[wholesale-campaigns][ui] save:error', {
@@ -2450,7 +2454,9 @@ function scheduleReload () {
async function fetchChunk ({ page = 1, useCache = true } = {}) {
const filters = buildServerFilters()
const hasAnyFilter = Object.values(filters).some((v) => Array.isArray(v) && v.length > 0)
const productCodeCount = Array.isArray(filters.product_code) ? filters.product_code.length : 0
const hasPrimaryFilter = (filters.urun_ilk_grubu?.length || 0) > 0 || (filters.urun_ana_grubu?.length || 0) > 0
const hasNarrowProductFilter = productCodeCount > 0
if (!hasAnyFilter) {
// This endpoint is expensive without filters; require the user to scope down first.
store.rows = []
@@ -2462,7 +2468,7 @@ async function fetchChunk ({ page = 1, useCache = true } = {}) {
store.hasMore = false
return 0
}
if (!hasPrimaryFilter) {
if (!hasPrimaryFilter && !hasNarrowProductFilter) {
store.rows = []
variantRows.value = []
store.error = GUIDANCE_MSG
@@ -2472,8 +2478,11 @@ async function fetchChunk ({ page = 1, useCache = true } = {}) {
store.hasMore = false
return 0
}
const effectiveLimit = hasNarrowProductFilter
? Math.max(productCodeCount, 1)
: PAGE_LIMIT
const result = await store.fetchRows({
limit: PAGE_LIMIT,
limit: effectiveLimit,
page,
append: false,
silent: false,
@@ -2558,6 +2567,36 @@ function onRowCampaignChange (row, val) {
toggleRowSelection(rowSelectionKey(row), true)
}
function makeVariantRowsCacheKey (codes = []) {
return codes
.map((x) => String(x || '').trim())
.filter(Boolean)
.sort()
.join(',')
}
function getVariantRowsCache (key) {
if (!key || !variantRowsCache.has(key)) return null
const cached = variantRowsCache.get(key)
variantRowsCache.delete(key)
variantRowsCache.set(key, cached)
return Array.isArray(cached) ? cached.map((x) => ({ ...x })) : null
}
function putVariantRowsCache (key, rows = []) {
if (!key) return
variantRowsCache.set(key, Array.isArray(rows) ? rows.map((x) => ({ ...x })) : [])
while (variantRowsCache.size > VARIANT_ROWS_CACHE_LIMIT) {
const oldest = variantRowsCache.keys().next().value
if (!oldest) break
variantRowsCache.delete(oldest)
}
}
function clearVariantRowsCache () {
variantRowsCache.clear()
}
async function buildVariantRowsForProductPage (baseProductRows = []) {
const base = Array.isArray(baseProductRows) ? baseProductRows : []
const codes = base.map((r) => String(r?.productCode || '').trim()).filter(Boolean)
@@ -2565,6 +2604,12 @@ async function buildVariantRowsForProductPage (baseProductRows = []) {
variantRows.value = []
return
}
const cacheKey = makeVariantRowsCacheKey(codes)
const cached = getVariantRowsCache(cacheKey)
if (cached) {
variantRows.value = cached
return
}
variantLoading.value = true
try {
@@ -2627,9 +2672,10 @@ async function buildVariantRowsForProductPage (baseProductRows = []) {
}
applyCampaignDerived(row)
out.push(row)
}
}
}
variantRows.value = out
putVariantRowsCache(cacheKey, out)
} catch (err) {
console.error('[wholesale-campaigns][ui] variant-rows:error', {
status: err?.response?.status ?? null,

View File

@@ -109,7 +109,8 @@ function normalizeFilters (filters = {}) {
}
function hasPrimaryFilter (filters = {}) {
return (Array.isArray(filters.urun_ilk_grubu) && filters.urun_ilk_grubu.length > 0) ||
return (Array.isArray(filters.product_code) && filters.product_code.length > 0) ||
(Array.isArray(filters.urun_ilk_grubu) && filters.urun_ilk_grubu.length > 0) ||
(Array.isArray(filters.urun_ana_grubu) && filters.urun_ana_grubu.length > 0)
}