Skip to content

Commit 16e9dec

Browse files
zeripathdelvh
andauthored
Fix Operator does not exist bug on explore page with ONLY_SHOW_RELEVANT_REPOS (#22454)
There is a mistake in the code for SearchRepositoryCondition where it tests topics as a string. This is incorrect for postgres where topics is cast and stored as json. topics needs to be cast to text for this to work. (For some reason JSON_ARRAY_LENGTH does not work, so I have taken the simplest solution of casting to text and doing a string comparison.) Ref #21962 (comment) Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: delvh <[email protected]>
1 parent 1e7f3c1 commit 16e9dec

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

models/repo/repo_list.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/models/unit"
1414
user_model "code.gitea.io/gitea/models/user"
1515
"code.gitea.io/gitea/modules/container"
16+
"code.gitea.io/gitea/modules/setting"
1617
"code.gitea.io/gitea/modules/structs"
1718
"code.gitea.io/gitea/modules/util"
1819

@@ -496,8 +497,12 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
496497
// Only show a repo that either has a topic or description.
497498
subQueryCond := builder.NewCond()
498499

499-
// Topic checking. Topics is non-null.
500-
subQueryCond = subQueryCond.Or(builder.And(builder.Neq{"topics": "null"}, builder.Neq{"topics": "[]"}))
500+
// Topic checking. Topics are present.
501+
if setting.Database.UsePostgreSQL { // postgres stores the topics as json and not as text
502+
subQueryCond = subQueryCond.Or(builder.And(builder.NotNull{"topics"}, builder.Neq{"(topics)::text": "[]"}))
503+
} else {
504+
subQueryCond = subQueryCond.Or(builder.And(builder.Neq{"topics": "null"}, builder.Neq{"topics": "[]"}))
505+
}
501506

502507
// Description checking. Description not empty.
503508
subQueryCond = subQueryCond.Or(builder.Neq{"description": ""})

0 commit comments

Comments
 (0)