From 3a361ef7965671369151e80c8a92c11be77cfb1e Mon Sep 17 00:00:00 2001 From: 1911860538 Date: Tue, 13 May 2025 23:13:47 +0800 Subject: [PATCH] perf: use strings.Cut to replace strings.SplitN --- callbacks/preload.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/callbacks/preload.go b/callbacks/preload.go index fd8214bb..a84065ff 100644 --- a/callbacks/preload.go +++ b/callbacks/preload.go @@ -103,11 +103,11 @@ func preloadEntryPoint(db *gorm.DB, joins []string, relationships *schema.Relati joined = true continue } - joinNames := strings.SplitN(join, ".", 2) - if len(joinNames) == 2 { - if _, ok := relationships.Relations[joinNames[0]]; ok && name == joinNames[0] { + join0, join1, cut := strings.Cut(join, ".") + if cut { + if _, ok := relationships.Relations[join0]; ok && name == join0 { joined = true - nestedJoins = append(nestedJoins, joinNames[1]) + nestedJoins = append(nestedJoins, join1) } } }