@@ -12,6 +12,7 @@ import (
1212 "strings"
1313
1414 "code.gitea.io/gitea/models/db"
15+ "code.gitea.io/gitea/modules/container"
1516 "code.gitea.io/gitea/modules/label"
1617 "code.gitea.io/gitea/modules/optional"
1718 "code.gitea.io/gitea/modules/timeutil"
@@ -143,37 +144,32 @@ func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
143144
144145// LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked
145146func (l * Label ) LoadSelectedLabelsAfterClick (currentSelectedLabels []int64 , currentSelectedExclusiveScopes []string ) {
146- labelQuerySlice := [] int64 {}
147+ labelQueryParams := container. Set [ string ] {}
147148 labelSelected := false
148- labelScope := l .ExclusiveScope ()
149- for i , s := range currentSelectedLabels {
150- if s == l .ID {
149+ exclusiveScope := l .ExclusiveScope ()
150+ for i , curSel := range currentSelectedLabels {
151+ if curSel == l .ID {
151152 labelSelected = true
152- } else if - s == l .ID {
153+ } else if - curSel == l .ID {
153154 labelSelected = true
154155 l .IsExcluded = true
155- } else if s != 0 {
156+ } else if curSel != 0 {
156157 // Exclude other labels in the same scope from selection
157- if s < 0 || labelScope == "" || labelScope != currentSelectedExclusiveScopes [i ] {
158- labelQuerySlice = append ( labelQuerySlice , s )
158+ if curSel < 0 || exclusiveScope == "" || exclusiveScope != currentSelectedExclusiveScopes [i ] {
159+ labelQueryParams . Add ( strconv . FormatInt ( curSel , 10 ) )
159160 }
160161 }
161162 }
162163
163164 if ! labelSelected {
164- labelQuerySlice = append ( labelQuerySlice , l .ID )
165+ labelQueryParams . Add ( strconv . FormatInt ( l .ID , 10 ) )
165166 }
166167 l .IsSelected = labelSelected
167168
168169 // Sort and deduplicate the ids to avoid the crawlers asking for the
169170 // same thing with simply a different order of parameters
170- slices .Sort (labelQuerySlice )
171- labelQuerySlice = slices .Compact (labelQuerySlice )
172- // Quick conversion (strings.Join() doesn't accept slices of Int64)
173- labelQuerySliceStrings := make ([]string , len (labelQuerySlice ))
174- for i , x := range labelQuerySlice {
175- labelQuerySliceStrings [i ] = strconv .FormatInt (x , 10 )
176- }
171+ labelQuerySliceStrings := labelQueryParams .Values ()
172+ slices .Sort (labelQuerySliceStrings ) // the sort is still needed because the underlying map of Set doesn't guarantee order
177173 l .QueryString = strings .Join (labelQuerySliceStrings , "," )
178174}
179175
@@ -187,7 +183,7 @@ func (l *Label) BelongsToRepo() bool {
187183 return l .RepoID > 0
188184}
189185
190- // Return scope substring of label name, or empty string if none exists
186+ // ExclusiveScope returns scope substring of label name, or empty string if none exists
191187func (l * Label ) ExclusiveScope () string {
192188 if ! l .Exclusive {
193189 return ""
0 commit comments