From bd8dbce39ee0ee2275af6c0a2f940ccef9043833 Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Fri, 13 Mar 2026 15:13:41 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/routes/product_images.go | 67 +++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/svc/routes/product_images.go b/svc/routes/product_images.go index 1348ec0..c22a5cb 100644 --- a/svc/routes/product_images.go +++ b/svc/routes/product_images.go @@ -186,9 +186,12 @@ ORDER BY defer rows.Close() items := make([]ProductImageItem, 0, 16) + rowDim1ByID := make(map[int64]string, 16) matchedByDim := make([]ProductImageItem, 0, 16) matchedByName := make([]ProductImageItem, 0, 16) matchedByNameDim1Only := make([]ProductImageItem, 0, 16) + dim1Upper := strings.ToUpper(strings.TrimSpace(dim1)) + dim3Upper := strings.ToUpper(strings.TrimSpace(dim3)) for rows.Next() { @@ -209,39 +212,44 @@ ORDER BY it.ContentURL = fmt.Sprintf("/api/product-images/%d/content", it.ID) items = append(items, it) + rowDim1ByID[it.ID] = strings.TrimSpace(rowDim1) dimMatched := true - if dim1 != "" { + if dim1Upper != "" { // Bazı eski kayıtlarda dimval1 gerçek renk kodu yerine numeric id tutulmuş olabilir. // Bu yüzden dimval karşılaştırması yardımcı; asıl fallback file_name token eşleşmesidir. - dimMatched = dimMatched && (rowDim1 == strings.ToUpper(dim1)) + dimMatched = dimMatched && (rowDim1 == dim1Upper) } - if dim3 != "" { - dimMatched = dimMatched && (rowDim3 == strings.ToUpper(dim3) || rowDim2 == strings.ToUpper(dim3)) + if dim3Upper != "" { + dimMatched = dimMatched && (rowDim3 == dim3Upper || rowDim2 == dim3Upper) } if dimMatched { matchedByDim = append(matchedByDim, it) } - if imageFileMatches(it.FileName, dim1, dim3) { + if imageFileMatches(it.FileName, dim1Upper, dim3Upper) { matchedByName = append(matchedByName, it) } - if dim1 != "" && imageFileMatches(it.FileName, dim1, "") { + if dim1Upper != "" && imageFileMatches(it.FileName, dim1Upper, "") { matchedByNameDim1Only = append(matchedByNameDim1Only, it) } } - if dim1 != "" || dim3 != "" { - if len(matchedByDim) > 0 { - items = matchedByDim - } else if len(matchedByName) > 0 { - items = matchedByName - } else if dim3 == "" && len(matchedByNameDim1Only) > 0 { - // Sadece 1. renk filtreleniyorsa dim1-only fallback kabul. - items = matchedByNameDim1Only - } else if dim3 != "" && len(matchedByNameDim1Only) > 0 { - // dim3 verilmis ama kayitlar eski tek-renk adlandirma kullaniyor olabilir. - // Eger dosya adlarinda "001_1" gibi ikinci renk pattern'i yoksa dim1-only fallback kabul. + if dim1Upper != "" || dim3Upper != "" { + targetDimval1 := make(map[string]struct{}, 4) + for _, it := range matchedByName { + if dv := rowDim1ByID[it.ID]; dv != "" { + targetDimval1[dv] = struct{}{} + } + } + if len(targetDimval1) == 0 && dim3Upper == "" { + for _, it := range matchedByNameDim1Only { + if dv := rowDim1ByID[it.ID]; dv != "" { + targetDimval1[dv] = struct{}{} + } + } + } + if len(targetDimval1) == 0 && dim3Upper != "" && len(matchedByNameDim1Only) > 0 { hasDim3Pattern := false for _, it := range matchedByNameDim1Only { if imageFileHasDim3Pattern(it.FileName) { @@ -250,12 +258,29 @@ ORDER BY } } if !hasDim3Pattern { - items = matchedByNameDim1Only - } else { - items = []ProductImageItem{} + for _, it := range matchedByNameDim1Only { + if dv := rowDim1ByID[it.ID]; dv != "" { + targetDimval1[dv] = struct{}{} + } + } } + } + + if len(targetDimval1) > 0 { + clustered := make([]ProductImageItem, 0, len(items)) + for _, it := range items { + if _, ok := targetDimval1[rowDim1ByID[it.ID]]; ok { + clustered = append(clustered, it) + } + } + items = clustered + } else if len(matchedByDim) > 0 { + items = matchedByDim + } else if len(matchedByName) > 0 { + items = matchedByName + } else if dim3Upper == "" && len(matchedByNameDim1Only) > 0 { + items = matchedByNameDim1Only } else { - // dim3 (2. renk) verildiyse yanlis varyanta dusmemek icin bos don. items = []ProductImageItem{} } }