From 31f42bd84ef2e70a29e46e5fe71c6a1186577276 Mon Sep 17 00:00:00 2001 From: delvh Date: Mon, 28 Nov 2022 15:27:55 +0100 Subject: [PATCH 1/2] Remove useless ONLY_SHOW_RELEVANT_REPOS setting The user can already disable the filter manually, so the explicit setting is absolutely useless and only complicates the logic. Additionally, previously there was unexpected behavior when multiple query parameters were present. --- .gitignore | 3 +++ custom/conf/app.example.ini | 4 ---- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 -- models/repo/repo_list.go | 10 +++++----- modules/setting/setting.go | 2 -- routers/web/explore/repo.go | 9 ++++----- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 1ce2a87611e8..3943102b749a 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,6 @@ prime/ # Manpage /man + +# tags file, simply due to its size (>18MB) +tags diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 5822dc1e4a85..efa448f31261 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1209,10 +1209,6 @@ ROUTER = console ;; ;; Whether to enable a Service Worker to cache frontend assets ;USE_SERVICE_WORKER = false -;; -;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. -;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). -;ONLY_SHOW_RELEVANT_REPOS = false ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 853f0c67f254..07d1bc84e007 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -228,8 +228,6 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. - `USE_SERVICE_WORKER`: **false**: Whether to enable a Service Worker to cache frontend assets. -- `ONLY_SHOW_RELEVANT_REPOS`: **false** Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. - A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). ### UI - Admin (`ui.admin`) diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index 6d9dd9ec65ac..61eee7a125b6 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -494,19 +494,19 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { } if opts.OnlyShowRelevant { - // Only show a repo that either has a topic or description. + // Only show a repo that has at least a topic, an icon, or a description subQueryCond := builder.NewCond() - // Topic checking. Topics is non-null. + // Topic checking. Topics is non-null subQueryCond = subQueryCond.Or(builder.And(builder.Neq{"topics": "null"}, builder.Neq{"topics": "[]"})) - // Description checking. Description not empty. + // Description checking. Description not empty subQueryCond = subQueryCond.Or(builder.Neq{"description": ""}) - // Repo has a avatar. + // Repo has a avatar subQueryCond = subQueryCond.Or(builder.Neq{"avatar": ""}) - // Always hide repo's that are empty. + // Always hide repo's that are empty subQueryCond = subQueryCond.And(builder.Eq{"is_empty": false}) cond = cond.And(subQueryCond) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 68892a219825..74b89fa1764c 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -240,7 +240,6 @@ var ( CustomEmojisMap map[string]string `ini:"-"` SearchRepoDescription bool UseServiceWorker bool - OnlyShowRelevantRepos bool Notification struct { MinTimeout time.Duration @@ -1108,7 +1107,6 @@ func loadFromConf(allowEmpty bool, extraConfig string) { UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false) UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true) UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(false) - UI.OnlyShowRelevantRepos = Cfg.Section("ui").Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false) HasRobotsTxt, err = util.IsFile(path.Join(CustomPath, "robots.txt")) if err != nil { diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index 5271e39bbc91..63be2c102fc1 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -18,6 +18,7 @@ import ( const ( // tplExploreRepos explore repositories page template tplExploreRepos base.TplName = "explore/repos" + relevantReposOnlyParam = "no_filter" ) // RepoSearchOptions when calling search repositories @@ -81,13 +82,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { default: ctx.Data["SortType"] = "recentupdate" orderBy = db.SearchOrderByRecentUpdated - onlyShowRelevant = setting.UI.OnlyShowRelevantRepos && !ctx.FormBool("no_filter") } + onlyShowRelevant = !ctx.FormBool(relevantReposOnlyParam) + keyword := ctx.FormTrim("q") - if keyword != "" { - onlyShowRelevant = false - } ctx.Data["OnlyShowRelevant"] = onlyShowRelevant @@ -139,7 +138,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { pager.SetDefaultParams(ctx) pager.AddParam(ctx, "topic", "TopicOnly") pager.AddParam(ctx, "language", "Language") - pager.AddParamString("no_filter", ctx.FormString("no_filter")) + pager.AddParamString(relevantReposOnlyParam, ctx.FormString(relevantReposOnlyParam)) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, opts.TplName) From df9a0d7e057ef48cc8ffd8e09e4a30db3ebbf960 Mon Sep 17 00:00:00 2001 From: delvh Date: Mon, 28 Nov 2022 16:24:10 +0100 Subject: [PATCH 2/2] Fix lint --- routers/web/explore/repo.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index 63be2c102fc1..e9684dd2865d 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -17,8 +17,8 @@ import ( const ( // tplExploreRepos explore repositories page template - tplExploreRepos base.TplName = "explore/repos" - relevantReposOnlyParam = "no_filter" + tplExploreRepos base.TplName = "explore/repos" + relevantReposOnlyParam string = "no_filter" ) // RepoSearchOptions when calling search repositories