From e895be836d830b67dab5a996eb75fba6cf76aff3 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 15 Jan 2023 13:42:51 +0000 Subject: [PATCH 1/2] Fix Operator does not exist bug on explore page with ONLY_SHOW_RELEVANT_REPOS 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 https://github.com/go-gitea/gitea/pull/21962#issuecomment-1379584057 Signed-off-by: Andrew Thornton --- models/repo/repo_list.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index 9922ff25a2f0e..60cf94d10e0e4 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -13,6 +13,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" @@ -497,7 +498,11 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { subQueryCond := builder.NewCond() // Topic checking. Topics is non-null. - subQueryCond = subQueryCond.Or(builder.And(builder.Neq{"topics": "null"}, builder.Neq{"topics": "[]"})) + if setting.Database.UsePostgreSQL { + 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": ""}) From 1832d73b77bc2bbce7fd1c9ec16672abaab4c547 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 15 Jan 2023 13:59:28 +0000 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: delvh --- models/repo/repo_list.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index 60cf94d10e0e4..c6e9a204d1330 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -497,8 +497,8 @@ 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. - if setting.Database.UsePostgreSQL { + // 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": "[]"}))