Skip to content

Commit

Permalink
Fix Operator does not exist bug on explore page with ONLY_SHOW_RELEVA…
Browse files Browse the repository at this point in the history
…NT_REPOS (go-gitea#22454)

Backport go-gitea#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 go-gitea#21962 (comment)

Signed-off-by: Andrew Thornton <[email protected]>
Co-authored-by: delvh <[email protected]>
  • Loading branch information
zeripath and delvh committed Jan 16, 2023
1 parent 29bbfcc commit 3990211
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions models/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"

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

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

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

0 comments on commit 3990211

Please sign in to comment.