@@ -7,10 +7,12 @@ package issues
77import (
88 "context"
99 "fmt"
10+ "slices"
1011 "strconv"
1112 "strings"
1213
1314 "code.gitea.io/gitea/models/db"
15+ "code.gitea.io/gitea/modules/container"
1416 "code.gitea.io/gitea/modules/label"
1517 "code.gitea.io/gitea/modules/optional"
1618 "code.gitea.io/gitea/modules/timeutil"
@@ -142,28 +144,32 @@ func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
142144
143145// LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked
144146func (l * Label ) LoadSelectedLabelsAfterClick (currentSelectedLabels []int64 , currentSelectedExclusiveScopes []string ) {
145- var labelQuerySlice [] string
147+ labelQueryParams := container. Set [ string ]{}
146148 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 {
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 , strconv .FormatInt (s , 10 ))
158+ if curSel < 0 || exclusiveScope == "" || exclusiveScope != currentSelectedExclusiveScopes [i ] {
159+ labelQueryParams . Add ( strconv .FormatInt (curSel , 10 ))
159160 }
160161 }
161162 }
162163 if ! labelSelected {
163- labelQuerySlice = append ( labelQuerySlice , labelID )
164+ labelQueryParams . Add ( strconv . FormatInt ( l . ID , 10 ) )
164165 }
165166 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 , "," )
167173}
168174
169175// BelongsToOrg returns true if label is an organization label
@@ -176,7 +182,7 @@ func (l *Label) BelongsToRepo() bool {
176182 return l .RepoID > 0
177183}
178184
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
180186func (l * Label ) ExclusiveScope () string {
181187 if ! l .Exclusive {
182188 return ""
0 commit comments