Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
99f6dfc8
Commit
99f6dfc8
authored
Feb 11, 2022
by
Jonas Wälter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change the order column of topics to non_private_projects_count
Changelog: changed
parent
1cdc91a9
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
36 additions
and
20 deletions
+36
-20
app/finders/projects/topics_finder.rb
app/finders/projects/topics_finder.rb
+1
-1
app/graphql/resolvers/topics_resolver.rb
app/graphql/resolvers/topics_resolver.rb
+2
-2
app/models/projects/topic.rb
app/models/projects/topic.rb
+2
-2
db/migrate/20220211090920_cleanup_populate_topics_non_private_projects_count.rb
...920_cleanup_populate_topics_non_private_projects_count.rb
+15
-0
db/schema_migrations/20220211090920
db/schema_migrations/20220211090920
+1
-0
spec/finders/projects/topics_finder_spec.rb
spec/finders/projects/topics_finder_spec.rb
+3
-3
spec/graphql/resolvers/topics_resolver_spec.rb
spec/graphql/resolvers/topics_resolver_spec.rb
+3
-3
spec/models/projects/topic_spec.rb
spec/models/projects/topic_spec.rb
+6
-6
spec/requests/api/topics_spec.rb
spec/requests/api/topics_spec.rb
+3
-3
No files found.
app/finders/projects/topics_finder.rb
View file @
99f6dfc8
...
...
@@ -12,7 +12,7 @@ module Projects
end
def
execute
topics
=
Projects
::
Topic
.
order_by_
total
_projects_count
topics
=
Projects
::
Topic
.
order_by_
non_private
_projects_count
by_search
(
topics
)
end
...
...
app/graphql/resolvers/topics_resolver.rb
View file @
99f6dfc8
...
...
@@ -10,9 +10,9 @@ module Resolvers
def
resolve
(
**
args
)
if
args
[
:search
].
present?
::
Projects
::
Topic
.
search
(
args
[
:search
]).
order_by_
total
_projects_count
::
Projects
::
Topic
.
search
(
args
[
:search
]).
order_by_
non_private
_projects_count
else
::
Projects
::
Topic
.
order_by_
total
_projects_count
::
Projects
::
Topic
.
order_by_
non_private
_projects_count
end
end
end
...
...
app/models/projects/topic.rb
View file @
99f6dfc8
...
...
@@ -13,12 +13,12 @@ module Projects
has_many
:project_topics
,
class_name:
'Projects::ProjectTopic'
has_many
:projects
,
through: :project_topics
scope
:order_by_
total_projects_count
,
->
{
order
(
total
_projects_count: :desc
).
order
(
id: :asc
)
}
scope
:order_by_
non_private_projects_count
,
->
{
order
(
non_private
_projects_count: :desc
).
order
(
id: :asc
)
}
scope
:reorder_by_similarity
,
->
(
search
)
do
order_expression
=
Gitlab
::
Database
::
SimilarityScore
.
build_expression
(
search:
search
,
rules:
[
{
column:
arel_table
[
'name'
]
}
])
reorder
(
order_expression
.
desc
,
arel_table
[
'
total
_projects_count'
].
desc
,
arel_table
[
'id'
])
reorder
(
order_expression
.
desc
,
arel_table
[
'
non_private
_projects_count'
].
desc
,
arel_table
[
'id'
])
end
class
<<
self
...
...
db/migrate/20220211090920_cleanup_populate_topics_non_private_projects_count.rb
0 → 100644
View file @
99f6dfc8
# frozen_string_literal: true
class
CleanupPopulateTopicsNonPrivateProjectsCount
<
Gitlab
::
Database
::
Migration
[
1.0
]
MIGRATION
=
'PopulateTopicsNonPrivateProjectsCount'
disable_ddl_transaction!
def
up
finalize_background_migration
(
MIGRATION
)
end
def
down
# no-op
end
end
db/schema_migrations/20220211090920
0 → 100644
View file @
99f6dfc8
644d38e401ac8179777cb9d3c5fefca2fb55e0c409197bb2d222f7e96e5dd42f
\ No newline at end of file
spec/finders/projects/topics_finder_spec.rb
View file @
99f6dfc8
...
...
@@ -9,9 +9,9 @@ RSpec.describe Projects::TopicsFinder do
let!
(
:topic2
)
{
create
(
:topic
,
name:
'topicC'
)
}
let!
(
:topic3
)
{
create
(
:topic
,
name:
'topicA'
)
}
let!
(
:project1
)
{
create
(
:project
,
namespace:
user
.
namespace
,
topic_list:
'topicC, topicA, topicB'
)
}
let!
(
:project2
)
{
create
(
:project
,
namespace:
user
.
namespace
,
topic_list:
'topicC, topicA'
)
}
let!
(
:project3
)
{
create
(
:project
,
namespace:
user
.
namespace
,
topic_list:
'topicC'
)
}
let!
(
:project1
)
{
create
(
:project
,
:public
,
namespace:
user
.
namespace
,
topic_list:
'topicC, topicA, topicB'
)
}
let!
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
user
.
namespace
,
topic_list:
'topicC, topicA'
)
}
let!
(
:project3
)
{
create
(
:project
,
:public
,
namespace:
user
.
namespace
,
topic_list:
'topicC'
)
}
describe
'#execute'
do
it
'returns topics'
do
...
...
spec/graphql/resolvers/topics_resolver_spec.rb
View file @
99f6dfc8
...
...
@@ -6,9 +6,9 @@ RSpec.describe Resolvers::TopicsResolver do
include
GraphqlHelpers
describe
'#resolve'
do
let!
(
:topic1
)
{
create
(
:topic
,
name:
'GitLab'
,
total
_projects_count:
1
)
}
let!
(
:topic2
)
{
create
(
:topic
,
name:
'git'
,
total
_projects_count:
2
)
}
let!
(
:topic3
)
{
create
(
:topic
,
name:
'topic3'
,
total
_projects_count:
3
)
}
let!
(
:topic1
)
{
create
(
:topic
,
name:
'GitLab'
,
non_private
_projects_count:
1
)
}
let!
(
:topic2
)
{
create
(
:topic
,
name:
'git'
,
non_private
_projects_count:
2
)
}
let!
(
:topic3
)
{
create
(
:topic
,
name:
'topic3'
,
non_private
_projects_count:
3
)
}
it
'finds all topics'
do
expect
(
resolve_topics
).
to
eq
([
topic3
,
topic2
,
topic1
])
...
...
spec/models/projects/topic_spec.rb
View file @
99f6dfc8
...
...
@@ -28,16 +28,16 @@ RSpec.describe Projects::Topic do
end
describe
'scopes'
do
describe
'order_by_
total
_projects_count'
do
describe
'order_by_
non_private
_projects_count'
do
let!
(
:topic1
)
{
create
(
:topic
,
name:
'topicB'
)
}
let!
(
:topic2
)
{
create
(
:topic
,
name:
'topicC'
)
}
let!
(
:topic3
)
{
create
(
:topic
,
name:
'topicA'
)
}
let!
(
:project1
)
{
create
(
:project
,
topic_list:
'topicC, topicA, topicB'
)
}
let!
(
:project2
)
{
create
(
:project
,
topic_list:
'topicC, topicA'
)
}
let!
(
:project3
)
{
create
(
:project
,
topic_list:
'topicC'
)
}
let!
(
:project1
)
{
create
(
:project
,
:public
,
topic_list:
'topicC, topicA, topicB'
)
}
let!
(
:project2
)
{
create
(
:project
,
:public
,
topic_list:
'topicC, topicA'
)
}
let!
(
:project3
)
{
create
(
:project
,
:public
,
topic_list:
'topicC'
)
}
it
'sorts topics by
total
_projects_count'
do
topics
=
described_class
.
order_by_
total
_projects_count
it
'sorts topics by
non_private
_projects_count'
do
topics
=
described_class
.
order_by_
non_private
_projects_count
expect
(
topics
.
map
(
&
:name
)).
to
eq
(
%w[topicC topicA topicB topic]
)
end
...
...
spec/requests/api/topics_spec.rb
View file @
99f6dfc8
...
...
@@ -7,9 +7,9 @@ RSpec.describe API::Topics do
let_it_be
(
:file
)
{
fixture_file_upload
(
'spec/fixtures/dk.png'
)
}
let_it_be
(
:topic_1
)
{
create
(
:topic
,
name:
'Git'
,
total_projects_count:
1
,
avatar:
file
)
}
let_it_be
(
:topic_2
)
{
create
(
:topic
,
name:
'GitLab'
,
total_projects_count:
2
)
}
let_it_be
(
:topic_3
)
{
create
(
:topic
,
name:
'other-topic'
,
total_projects_count:
3
)
}
let_it_be
(
:topic_1
)
{
create
(
:topic
,
name:
'Git'
,
total_projects_count:
1
,
non_private_projects_count:
1
,
avatar:
file
)
}
let_it_be
(
:topic_2
)
{
create
(
:topic
,
name:
'GitLab'
,
total_projects_count:
2
,
non_private_projects_count:
2
)
}
let_it_be
(
:topic_3
)
{
create
(
:topic
,
name:
'other-topic'
,
total_projects_count:
3
,
non_private_projects_count:
3
)
}
let_it_be
(
:admin
)
{
create
(
:user
,
:admin
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment