Skip to content

Commit af8151c

Browse files
authored
Fix Operator does not exist bug on explore page with ONLY_SHOW_RELEVANT_REPOS (#22454) (#22472)
Backport #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]>
1 parent ee37edc commit af8151c

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
@@ -15,6 +15,7 @@ import (
1515
"code.gitea.io/gitea/models/unit"
1616
user_model "code.gitea.io/gitea/models/user"
1717
"code.gitea.io/gitea/modules/container"
18+
"code.gitea.io/gitea/modules/setting"
1819
"code.gitea.io/gitea/modules/structs"
1920
"code.gitea.io/gitea/modules/util"
2021

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

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

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

0 commit comments

Comments
 (0)