Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -655,6 +655,23 @@ func chunkStringSlice(values []string, size int) [][]string {
|
||||
return out
|
||||
}
|
||||
|
||||
func cleanProductPricingFilterValues(values []string) []string {
|
||||
clean := make([]string, 0, len(values))
|
||||
seen := make(map[string]struct{}, len(values))
|
||||
for _, v := range values {
|
||||
v = strings.TrimSpace(v)
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[v]; ok {
|
||||
continue
|
||||
}
|
||||
seen[v] = struct{}{}
|
||||
clean = append(clean, v)
|
||||
}
|
||||
return clean
|
||||
}
|
||||
|
||||
func GetProductPricingPage(ctx context.Context, page int, limit int, filters ProductPricingFilters, includeTotal bool, sortBy string, descending bool) (ProductPricingPage, error) {
|
||||
result := ProductPricingPage{
|
||||
Rows: []models.ProductPricing{},
|
||||
@@ -770,7 +787,9 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
result.Limit = limit
|
||||
}
|
||||
|
||||
// Stage 1: fetch only paged products first (fast path).
|
||||
// Stage 1: fetch only paged products first. Exact product-code filters do not
|
||||
// need the stock sort temp table here; detailed metrics are fetched below.
|
||||
productCodeFastPath := len(cleanProductPricingFilterValues(filters.ProductCode)) > 0
|
||||
sortBy = strings.TrimSpace(sortBy)
|
||||
orderDir := "DESC"
|
||||
if !descending {
|
||||
@@ -857,6 +876,61 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
OFFSET ` + strconv.Itoa(offset) + ` ROWS
|
||||
FETCH NEXT ` + strconv.Itoa(limit) + ` ROWS ONLY;
|
||||
`
|
||||
if productCodeFastPath {
|
||||
productQuery = `
|
||||
IF OBJECT_ID('tempdb..#req_codes') IS NOT NULL DROP TABLE #req_codes;
|
||||
|
||||
SELECT
|
||||
f.ProductCode,
|
||||
MAX(f.BrandGroupSec) AS BrandGroupSec,
|
||||
MAX(f.AskiliYan) AS AskiliYan,
|
||||
MAX(f.Kategori) AS Kategori,
|
||||
MAX(f.UrunIlkGrubu) AS UrunIlkGrubu,
|
||||
MAX(f.UrunAnaGrubu) AS UrunAnaGrubu,
|
||||
MAX(f.UrunAltGrubu) AS UrunAltGrubu,
|
||||
MAX(f.Icerik) AS Icerik,
|
||||
MAX(f.Karisim) AS Karisim,
|
||||
MAX(f.Marka) AS Marka,
|
||||
MAX(f.BrandCode) AS BrandCode
|
||||
INTO #req_codes
|
||||
FROM (
|
||||
SELECT
|
||||
LTRIM(RTRIM(ProductCode)) AS ProductCode,
|
||||
` + brandGroupExpr + ` AS BrandGroupSec,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt45Desc)), '') AS AskiliYan,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt44Desc)), '') AS Kategori,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt42Desc)), '') AS UrunIlkGrubu,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt01Desc)), '') AS UrunAnaGrubu,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt02Desc)), '') AS UrunAltGrubu,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt41Desc)), '') AS Icerik,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt29Desc)), '') AS Karisim,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt10Desc)), '') AS Marka,
|
||||
COALESCE(LTRIM(RTRIM(ProductAtt10)), '') AS BrandCode
|
||||
FROM ProductFilterWithDescription('TR')
|
||||
WHERE ` + whereSQL + `
|
||||
) f
|
||||
GROUP BY f.ProductCode;
|
||||
|
||||
CREATE CLUSTERED INDEX IX_req_codes_ProductCode ON #req_codes(ProductCode);
|
||||
|
||||
SELECT
|
||||
rc.ProductCode,
|
||||
rc.BrandGroupSec,
|
||||
rc.AskiliYan,
|
||||
rc.Kategori,
|
||||
rc.UrunIlkGrubu,
|
||||
rc.UrunAnaGrubu,
|
||||
rc.UrunAltGrubu,
|
||||
rc.Icerik,
|
||||
rc.Karisim,
|
||||
rc.Marka,
|
||||
rc.BrandCode
|
||||
FROM #req_codes rc
|
||||
ORDER BY rc.ProductCode ASC
|
||||
OFFSET ` + strconv.Itoa(offset) + ` ROWS
|
||||
FETCH NEXT ` + strconv.Itoa(limit) + ` ROWS ONLY;
|
||||
`
|
||||
}
|
||||
|
||||
var (
|
||||
rows *sql.Rows
|
||||
|
||||
Reference in New Issue
Block a user