Skip to content

Commit f1a810e

Browse files
authored
Related refactors to ctx.FormX functions (#16567)
* use FormTrim if posible * speedup goGet * only convert if nessesary
1 parent 2d25b7d commit f1a810e

File tree

22 files changed

+36
-52
lines changed

22 files changed

+36
-52
lines changed

routers/api/v1/notify/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
171171
// "$ref": "#/responses/empty"
172172

173173
lastRead := int64(0)
174-
qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ")
174+
qLastRead := ctx.FormTrim("last_read_at")
175175
if len(qLastRead) > 0 {
176176
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
177177
if err != nil {

routers/api/v1/notify/user.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package notify
66

77
import (
88
"net/http"
9-
"strings"
109
"time"
1110

1211
"code.gitea.io/gitea/models"
@@ -122,7 +121,7 @@ func ReadNotifications(ctx *context.APIContext) {
122121
// "$ref": "#/responses/empty"
123122

124123
lastRead := int64(0)
125-
qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ")
124+
qLastRead := ctx.FormTrim("last_read_at")
126125
if len(qLastRead) > 0 {
127126
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
128127
if err != nil {

routers/api/v1/org/team.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package org
88
import (
99
"fmt"
1010
"net/http"
11-
"strings"
1211

1312
"code.gitea.io/gitea/models"
1413
"code.gitea.io/gitea/modules/context"
@@ -658,7 +657,7 @@ func SearchTeam(ctx *context.APIContext) {
658657

659658
opts := &models.SearchTeamOptions{
660659
UserID: ctx.User.ID,
661-
Keyword: strings.TrimSpace(ctx.FormString("q")),
660+
Keyword: ctx.FormTrim("q"),
662661
OrgID: ctx.Org.Organization.ID,
663662
IncludeDesc: ctx.FormString("include_desc") == "" || ctx.FormBool("include_desc"),
664663
ListOptions: listOptions,

routers/api/v1/repo/issue.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func SearchIssues(ctx *context.APIContext) {
140140
var issues []*models.Issue
141141
var filteredCount int64
142142

143-
keyword := strings.Trim(ctx.FormString("q"), " ")
143+
keyword := ctx.FormTrim("q")
144144
if strings.IndexByte(keyword, 0) >= 0 {
145145
keyword = ""
146146
}
@@ -162,13 +162,13 @@ func SearchIssues(ctx *context.APIContext) {
162162
isPull = util.OptionalBoolNone
163163
}
164164

165-
labels := strings.TrimSpace(ctx.FormString("labels"))
165+
labels := ctx.FormTrim("labels")
166166
var includedLabelNames []string
167167
if len(labels) > 0 {
168168
includedLabelNames = strings.Split(labels, ",")
169169
}
170170

171-
milestones := strings.TrimSpace(ctx.FormString("milestones"))
171+
milestones := ctx.FormTrim("milestones")
172172
var includedMilestones []string
173173
if len(milestones) > 0 {
174174
includedMilestones = strings.Split(milestones, ",")
@@ -331,7 +331,7 @@ func ListIssues(ctx *context.APIContext) {
331331
var issues []*models.Issue
332332
var filteredCount int64
333333

334-
keyword := strings.Trim(ctx.FormString("q"), " ")
334+
keyword := ctx.FormTrim("q")
335335
if strings.IndexByte(keyword, 0) >= 0 {
336336
keyword = ""
337337
}

routers/api/v1/repo/issue_tracked_time.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package repo
77
import (
88
"fmt"
99
"net/http"
10-
"strings"
1110
"time"
1211

1312
"code.gitea.io/gitea/models"
@@ -90,7 +89,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
9089
IssueID: issue.ID,
9190
}
9291

93-
qUser := strings.Trim(ctx.FormString("user"), " ")
92+
qUser := ctx.FormTrim("user")
9493
if qUser != "" {
9594
user, err := models.GetUserByName(qUser)
9695
if models.IsErrUserNotExist(err) {
@@ -500,7 +499,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
500499
}
501500

502501
// Filters
503-
qUser := strings.Trim(ctx.FormString("user"), " ")
502+
qUser := ctx.FormTrim("user")
504503
if qUser != "" {
505504
user, err := models.GetUserByName(qUser)
506505
if models.IsErrUserNotExist(err) {

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func Search(ctx *context.APIContext) {
135135
opts := &models.SearchRepoOptions{
136136
ListOptions: utils.GetListOptions(ctx),
137137
Actor: ctx.User,
138-
Keyword: strings.Trim(ctx.FormString("q"), " "),
138+
Keyword: ctx.FormTrim("q"),
139139
OwnerID: ctx.FormInt64("uid"),
140140
PriorityOwnerID: ctx.FormInt64("priority_owner_id"),
141141
TeamID: ctx.FormInt64("team_id"),

routers/api/v1/user/user.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package user
88
import (
99
"fmt"
1010
"net/http"
11-
"strings"
1211

1312
"code.gitea.io/gitea/models"
1413
"code.gitea.io/gitea/modules/context"
@@ -58,7 +57,7 @@ func Search(ctx *context.APIContext) {
5857

5958
opts := &models.SearchUserOptions{
6059
Actor: ctx.User,
61-
Keyword: strings.Trim(ctx.FormString("q"), " "),
60+
Keyword: ctx.FormTrim("q"),
6261
UID: ctx.FormInt64("uid"),
6362
Type: models.UserTypeIndividual,
6463
ListOptions: listOptions,

routers/web/admin/repos.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package admin
77
import (
88
"net/http"
99
"net/url"
10-
"strconv"
1110
"strings"
1211

1312
"code.gitea.io/gitea/models"
@@ -111,7 +110,7 @@ func UnadoptedRepos(ctx *context.Context) {
111110
func AdoptOrDeleteRepository(ctx *context.Context) {
112111
dir := ctx.FormString("id")
113112
action := ctx.FormString("action")
114-
page := ctx.FormInt("page")
113+
page := ctx.FormString("page")
115114
q := ctx.FormString("q")
116115

117116
dirSplit := strings.SplitN(dir, "/", 2)
@@ -162,5 +161,5 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
162161
}
163162
ctx.Flash.Success(ctx.Tr("repo.delete_preexisting_success", dir))
164163
}
165-
ctx.Redirect(setting.AppSubURL + "/admin/repos/unadopted?search=true&q=" + url.QueryEscape(q) + "&page=" + strconv.Itoa(page))
164+
ctx.Redirect(setting.AppSubURL + "/admin/repos/unadopted?search=true&q=" + url.QueryEscape(q) + "&page=" + page)
166165
}

routers/web/explore/code.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package explore
66

77
import (
88
"net/http"
9-
"strings"
109

1110
"code.gitea.io/gitea/models"
1211
"code.gitea.io/gitea/modules/base"
@@ -33,14 +32,14 @@ func Code(ctx *context.Context) {
3332
ctx.Data["PageIsExplore"] = true
3433
ctx.Data["PageIsExploreCode"] = true
3534

36-
language := strings.TrimSpace(ctx.FormString("l"))
37-
keyword := strings.TrimSpace(ctx.FormString("q"))
35+
language := ctx.FormTrim("l")
36+
keyword := ctx.FormTrim("q")
3837
page := ctx.FormInt("page")
3938
if page <= 0 {
4039
page = 1
4140
}
4241

43-
queryType := strings.TrimSpace(ctx.FormString("t"))
42+
queryType := ctx.FormTrim("t")
4443
isMatch := queryType == "match"
4544

4645
var (

routers/web/explore/repo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package explore
66

77
import (
88
"net/http"
9-
"strings"
109

1110
"code.gitea.io/gitea/models"
1211
"code.gitea.io/gitea/modules/base"
@@ -73,7 +72,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
7372
orderBy = models.SearchOrderByRecentUpdated
7473
}
7574

76-
keyword := strings.Trim(ctx.FormString("q"), " ")
75+
keyword := ctx.FormTrim("q")
7776
topicOnly := ctx.FormBool("topic")
7877
ctx.Data["TopicOnly"] = topicOnly
7978

0 commit comments

Comments
 (0)