summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-08-25 20:38:41 +0200
committerGitHub <noreply@github.com>2022-08-25 20:38:41 +0200
commit27ac65a124f34ec3ed5f34aeb576f918ae1c70b1 (patch)
tree2c31f4d30e5bfce87056c397fcdae6c6e86c5788 /models
parentdc0253b0637bbf367ad330612900e780c6b2b0e6 (diff)
downloadgitea-27ac65a124f34ec3ed5f34aeb576f918ae1c70b1.tar.gz
gitea-27ac65a124f34ec3ed5f34aeb576f918ae1c70b1.zip
Only show relevant repositories on explore page (#19361)
Adds a new option to only show relevant repo's on the explore page, for bigger Gitea instances like Codeberg this is a nice option to enable to make the explore page more populated with unique and "high" quality repo's. A note is shown that the results are filtered and have the possibility to see the unfiltered results. Co-authored-by: vednoc <vednoc@protonmail.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models')
-rw-r--r--models/repo/repo_list.go31
1 files changed, 29 insertions, 2 deletions
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go
index 1fa469fcfe..ee72dc6ee7 100644
--- a/models/repo/repo_list.go
+++ b/models/repo/repo_list.go
@@ -163,6 +163,10 @@ type SearchRepoOptions struct {
HasMilestones util.OptionalBool
// LowerNames represents valid lower names to restrict to
LowerNames []string
+ // When specified true, apply some filters over the conditions:
+ // - Don't show forks, when opts.Fork is OptionalBoolNone.
+ // - Do not display repositories that don't have a description, an icon and topics.
+ OnlyShowRelevant bool
}
// SearchOrderBy is used to sort the result
@@ -463,8 +467,12 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
Where(builder.Eq{"language": opts.Language}).And(builder.Eq{"is_primary": true})))
}
- if opts.Fork != util.OptionalBoolNone {
- cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
+ if opts.Fork != util.OptionalBoolNone || opts.OnlyShowRelevant {
+ if opts.OnlyShowRelevant && opts.Fork == util.OptionalBoolNone {
+ cond = cond.And(builder.Eq{"is_fork": false})
+ } else {
+ cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
+ }
}
if opts.Mirror != util.OptionalBoolNone {
@@ -486,6 +494,25 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
cond = cond.And(builder.Eq{"num_milestones": 0}.Or(builder.IsNull{"num_milestones"}))
}
+ if opts.OnlyShowRelevant {
+ // 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": "[]"}))
+
+ // Description checking. Description not empty.
+ subQueryCond = subQueryCond.Or(builder.Neq{"description": ""})
+
+ // Repo has a avatar.
+ subQueryCond = subQueryCond.Or(builder.Neq{"avatar": ""})
+
+ // Always hide repo's that are empty.
+ subQueryCond = subQueryCond.And(builder.Eq{"is_empty": false})
+
+ cond = cond.And(subQueryCond)
+ }
+
return cond
}