Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-03-13 15:13:41 +03:00
parent 1063ec6e97
commit bd8dbce39e

View File

@@ -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,14 +258,31 @@ ORDER BY
}
}
if !hasDim3Pattern {
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 {
items = []ProductImageItem{}
}
} else {
// dim3 (2. renk) verildiyse yanlis varyanta dusmemek icin bos don.
items = []ProductImageItem{}
}
}
slog.Info("product_images.list.ok",