@@ -12,6 +12,7 @@ import (
12
12
"strings"
13
13
14
14
"code.gitea.io/gitea/models/db"
15
+ "code.gitea.io/gitea/modules/container"
15
16
"code.gitea.io/gitea/modules/label"
16
17
"code.gitea.io/gitea/modules/optional"
17
18
"code.gitea.io/gitea/modules/timeutil"
@@ -143,37 +144,32 @@ func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
143
144
144
145
// LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked
145
146
func (l * Label ) LoadSelectedLabelsAfterClick (currentSelectedLabels []int64 , currentSelectedExclusiveScopes []string ) {
146
- labelQuerySlice := [] int64 {}
147
+ labelQueryParams := container. Set [ string ] {}
147
148
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 {
151
152
labelSelected = true
152
- } else if - s == l .ID {
153
+ } else if - curSel == l .ID {
153
154
labelSelected = true
154
155
l .IsExcluded = true
155
- } else if s != 0 {
156
+ } else if curSel != 0 {
156
157
// 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 ) )
159
160
}
160
161
}
161
162
}
162
163
163
164
if ! labelSelected {
164
- labelQuerySlice = append ( labelQuerySlice , l .ID )
165
+ labelQueryParams . Add ( strconv . FormatInt ( l .ID , 10 ) )
165
166
}
166
167
l .IsSelected = labelSelected
167
168
168
169
// Sort and deduplicate the ids to avoid the crawlers asking for the
169
170
// 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
177
173
l .QueryString = strings .Join (labelQuerySliceStrings , "," )
178
174
}
179
175
@@ -187,7 +183,7 @@ func (l *Label) BelongsToRepo() bool {
187
183
return l .RepoID > 0
188
184
}
189
185
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
191
187
func (l * Label ) ExclusiveScope () string {
192
188
if ! l .Exclusive {
193
189
return ""
0 commit comments