loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: make author search case insenstive (#6782)

- Make the author search in the issues and pull request list case
insenstive.
- Background: Forgejo mandates that all columns are case senstive and
only SQLite ignores this for ASCII characters with the `LIKE` operator
any other database will indeed do case senstive searching. Codeberg
recently made all columns case senstive, hence why this issue now surfaces.
- Added integration test.
- Resolves forgejo/forgejo#6744

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6782
Reviewed-by: Beowulf <beowulf@beocode.eu>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>

authored by

Gusted
Gusted
and committed by
Gusted
499497c9 5b26596c

+45 -2
+2 -2
models/repo/user_repo.go
··· 166 166 // If isShowFullName is set to true, also include full name prefix search 167 167 func GetIssuePostersWithSearch(ctx context.Context, repo *Repository, isPull bool, search string, isShowFullName bool) ([]*user_model.User, error) { 168 168 users := make([]*user_model.User, 0, 30) 169 - var prefixCond builder.Cond = builder.Like{"name", search + "%"} 169 + prefixCond := db.BuildCaseInsensitiveLike("name", search+"%") 170 170 if isShowFullName { 171 - prefixCond = prefixCond.Or(builder.Like{"full_name", "%" + search + "%"}) 171 + prefixCond = db.BuildCaseInsensitiveLike("full_name", "%"+search+"%") 172 172 } 173 173 174 174 cond := builder.In("`user`.id",
+43
tests/integration/issue_test.go
··· 1336 1336 allCount := htmlDoc.doc.Find("a[data-test-name='all-issue-count']").Text() 1337 1337 assert.Contains(t, allCount, "2\u00a0All") 1338 1338 } 1339 + 1340 + func TestIssuePostersSearch(t *testing.T) { 1341 + defer tests.PrepareTestEnv(t)() 1342 + 1343 + type userSearchInfo struct { 1344 + UserID int64 `json:"user_id"` 1345 + UserName string `json:"username"` 1346 + } 1347 + 1348 + type userSearchResponse struct { 1349 + Results []*userSearchInfo `json:"results"` 1350 + } 1351 + 1352 + t.Run("Name search", func(t *testing.T) { 1353 + defer tests.PrintCurrentTest(t)() 1354 + defer test.MockVariableValue(&setting.UI.DefaultShowFullName, false)() 1355 + 1356 + req := NewRequest(t, "GET", "/user2/repo1/issues/posters?q=USer2") 1357 + resp := MakeRequest(t, req, http.StatusOK) 1358 + 1359 + var data userSearchResponse 1360 + DecodeJSON(t, resp, &data) 1361 + 1362 + assert.Len(t, data.Results, 1) 1363 + assert.EqualValues(t, "user2", data.Results[0].UserName) 1364 + assert.EqualValues(t, 2, data.Results[0].UserID) 1365 + }) 1366 + 1367 + t.Run("Full name search", func(t *testing.T) { 1368 + defer tests.PrintCurrentTest(t)() 1369 + defer test.MockVariableValue(&setting.UI.DefaultShowFullName, true)() 1370 + 1371 + req := NewRequest(t, "GET", "/user2/repo1/issues/posters?q=OnE") 1372 + resp := MakeRequest(t, req, http.StatusOK) 1373 + 1374 + var data userSearchResponse 1375 + DecodeJSON(t, resp, &data) 1376 + 1377 + assert.Len(t, data.Results, 1) 1378 + assert.EqualValues(t, "user1", data.Results[0].UserName) 1379 + assert.EqualValues(t, 1, data.Results[0].UserID) 1380 + }) 1381 + }