@@ -7,10 +7,12 @@ package issues
7
7
import (
8
8
"context"
9
9
"fmt"
10
+ "slices"
10
11
"strconv"
11
12
"strings"
12
13
13
14
"code.gitea.io/gitea/models/db"
15
+ "code.gitea.io/gitea/modules/container"
14
16
"code.gitea.io/gitea/modules/label"
15
17
"code.gitea.io/gitea/modules/optional"
16
18
"code.gitea.io/gitea/modules/timeutil"
@@ -142,28 +144,32 @@ func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
142
144
143
145
// LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked
144
146
func (l * Label ) LoadSelectedLabelsAfterClick (currentSelectedLabels []int64 , currentSelectedExclusiveScopes []string ) {
145
- var labelQuerySlice [] string
147
+ labelQueryParams := container. Set [ string ]{}
146
148
labelSelected := false
147
- labelID := strconv .FormatInt (l .ID , 10 )
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 , strconv .FormatInt (s , 10 ))
158
+ if curSel < 0 || exclusiveScope == "" || exclusiveScope != currentSelectedExclusiveScopes [i ] {
159
+ labelQueryParams . Add ( strconv .FormatInt (curSel , 10 ))
159
160
}
160
161
}
161
162
}
162
163
if ! labelSelected {
163
- labelQuerySlice = append ( labelQuerySlice , labelID )
164
+ labelQueryParams . Add ( strconv . FormatInt ( l . ID , 10 ) )
164
165
}
165
166
l .IsSelected = labelSelected
166
- l .QueryString = strings .Join (labelQuerySlice , "," )
167
+
168
+ // Sort and deduplicate the ids to avoid the crawlers asking for the
169
+ // same thing with simply a different order of parameters
170
+ labelQuerySliceStrings := labelQueryParams .Values ()
171
+ slices .Sort (labelQuerySliceStrings ) // the sort is still needed because the underlying map of Set doesn't guarantee order
172
+ l .QueryString = strings .Join (labelQuerySliceStrings , "," )
167
173
}
168
174
169
175
// BelongsToOrg returns true if label is an organization label
@@ -176,7 +182,7 @@ func (l *Label) BelongsToRepo() bool {
176
182
return l .RepoID > 0
177
183
}
178
184
179
- // Return scope substring of label name, or empty string if none exists
185
+ // ExclusiveScope returns scope substring of label name, or empty string if none exists
180
186
func (l * Label ) ExclusiveScope () string {
181
187
if ! l .Exclusive {
182
188
return ""
0 commit comments