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
e87edb6b
Commit
e87edb6b
authored
Jul 14, 2021
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve sort by popularity for issues board
Changelog: performance
parent
983fe9da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
44 deletions
+74
-44
app/models/issue.rb
app/models/issue.rb
+14
-2
spec/models/concerns/awardable_spec.rb
spec/models/concerns/awardable_spec.rb
+42
-42
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+18
-0
No files found.
app/models/issue.rb
View file @
e87edb6b
...
...
@@ -196,11 +196,23 @@ class Issue < ApplicationRecord
end
end
# Alias to state machine .with_state_id method
# This needs to be defined after the state machine block to avoid errors
class
<<
self
extend
::
Gitlab
::
Utils
::
Override
# Alias to state machine .with_state_id method
# This needs to be defined after the state machine block to avoid errors
alias_method
:with_state
,
:with_state_id
alias_method
:with_states
,
:with_state_ids
override
:order_upvotes_desc
def
order_upvotes_desc
reorder
(
upvotes_count: :desc
)
end
override
:order_upvotes_asc
def
order_upvotes_asc
reorder
(
upvotes_count: :asc
)
end
end
def
self
.
relative_positioning_query_base
(
issue
)
...
...
spec/models/concerns/awardable_spec.rb
View file @
e87edb6b
...
...
@@ -3,64 +3,64 @@
require
'spec_helper'
RSpec
.
describe
Awardable
do
let!
(
:
issue
)
{
create
(
:issu
e
)
}
let!
(
:award_emoji
)
{
create
(
:award_emoji
,
:downvote
,
awardable:
issu
e
)
}
let!
(
:
note
)
{
create
(
:not
e
)
}
let!
(
:award_emoji
)
{
create
(
:award_emoji
,
:downvote
,
awardable:
not
e
)
}
describe
"Associations"
do
subject
{
build
(
:
issu
e
)
}
subject
{
build
(
:
not
e
)
}
it
{
is_expected
.
to
have_many
(
:award_emoji
).
dependent
(
:destroy
)
}
end
describe
"ClassMethods"
do
let!
(
:
issue2
)
{
create
(
:issu
e
)
}
let!
(
:award_emoji2
)
{
create
(
:award_emoji
,
awardable:
issu
e2
)
}
let!
(
:
note2
)
{
create
(
:not
e
)
}
let!
(
:award_emoji2
)
{
create
(
:award_emoji
,
awardable:
not
e2
)
}
describe
"orders"
do
it
"orders on upvotes"
do
expect
(
Issue
.
order_upvotes_desc
.
to_a
).
to
eq
[
issue2
,
issu
e
]
expect
(
Note
.
order_upvotes_desc
.
to_a
).
to
eq
[
note2
,
not
e
]
end
it
"orders on downvotes"
do
expect
(
Issue
.
order_downvotes_desc
.
to_a
).
to
eq
[
issue
,
issu
e2
]
expect
(
Note
.
order_downvotes_desc
.
to_a
).
to
eq
[
note
,
not
e2
]
end
end
describe
"#awarded"
do
it
"filters by user and emoji name"
do
expect
(
Issu
e
.
awarded
(
award_emoji
.
user
,
"thumbsup"
)).
to
be_empty
expect
(
Issue
.
awarded
(
award_emoji
.
user
,
"thumbsdown"
)).
to
eq
[
issu
e
]
expect
(
Issue
.
awarded
(
award_emoji2
.
user
,
"thumbsup"
)).
to
eq
[
issu
e2
]
expect
(
Issu
e
.
awarded
(
award_emoji2
.
user
,
"thumbsdown"
)).
to
be_empty
expect
(
Not
e
.
awarded
(
award_emoji
.
user
,
"thumbsup"
)).
to
be_empty
expect
(
Note
.
awarded
(
award_emoji
.
user
,
"thumbsdown"
)).
to
eq
[
not
e
]
expect
(
Note
.
awarded
(
award_emoji2
.
user
,
"thumbsup"
)).
to
eq
[
not
e2
]
expect
(
Not
e
.
awarded
(
award_emoji2
.
user
,
"thumbsdown"
)).
to
be_empty
end
it
"filters by user and any emoji"
do
issue3
=
create
(
:issu
e
)
create
(
:award_emoji
,
awardable:
issu
e3
,
name:
"star"
,
user:
award_emoji
.
user
)
create
(
:award_emoji
,
awardable:
issu
e3
,
name:
"star"
,
user:
award_emoji2
.
user
)
note3
=
create
(
:not
e
)
create
(
:award_emoji
,
awardable:
not
e3
,
name:
"star"
,
user:
award_emoji
.
user
)
create
(
:award_emoji
,
awardable:
not
e3
,
name:
"star"
,
user:
award_emoji2
.
user
)
expect
(
Issue
.
awarded
(
award_emoji
.
user
)).
to
contain_exactly
(
issue
,
issu
e3
)
expect
(
Issue
.
awarded
(
award_emoji2
.
user
)).
to
contain_exactly
(
issue2
,
issu
e3
)
expect
(
Note
.
awarded
(
award_emoji
.
user
)).
to
contain_exactly
(
note
,
not
e3
)
expect
(
Note
.
awarded
(
award_emoji2
.
user
)).
to
contain_exactly
(
note2
,
not
e3
)
end
end
describe
"#not_awarded"
do
it
"returns
issu
es not awarded by user"
do
expect
(
Issue
.
not_awarded
(
award_emoji
.
user
)).
to
eq
[
issu
e2
]
expect
(
Issue
.
not_awarded
(
award_emoji2
.
user
)).
to
eq
[
issu
e
]
it
"returns
not
es not awarded by user"
do
expect
(
Note
.
not_awarded
(
award_emoji
.
user
)).
to
eq
[
not
e2
]
expect
(
Note
.
not_awarded
(
award_emoji2
.
user
)).
to
eq
[
not
e
]
end
end
end
describe
"#upvotes"
do
it
"counts the number of upvotes"
do
expect
(
issu
e
.
upvotes
).
to
be
0
expect
(
not
e
.
upvotes
).
to
be
0
end
end
describe
"#downvotes"
do
it
"counts the number of downvotes"
do
expect
(
issu
e
.
downvotes
).
to
be
1
expect
(
not
e
.
downvotes
).
to
be
1
end
end
...
...
@@ -68,67 +68,67 @@ RSpec.describe Awardable do
let
(
:user
)
{
create
(
:user
)
}
before
do
issu
e
.
project
.
add_guest
(
user
)
not
e
.
project
.
add_guest
(
user
)
end
it
'is truthy when the user is allowed to award emoji'
do
expect
(
issu
e
.
user_can_award?
(
user
)).
to
be_truthy
expect
(
not
e
.
user_can_award?
(
user
)).
to
be_truthy
end
it
'is falsy when the project is archived'
do
issu
e
.
project
.
update!
(
archived:
true
)
not
e
.
project
.
update!
(
archived:
true
)
expect
(
issu
e
.
user_can_award?
(
user
)).
to
be_falsy
expect
(
not
e
.
user_can_award?
(
user
)).
to
be_falsy
end
end
describe
'querying award_emoji on an Awardable'
do
let
(
:
issue
)
{
create
(
:issu
e
)
}
let
(
:
note
)
{
create
(
:not
e
)
}
it
'sorts in ascending fashion'
do
create_list
(
:award_emoji
,
3
,
awardable:
issu
e
)
create_list
(
:award_emoji
,
3
,
awardable:
not
e
)
expect
(
issue
.
award_emoji
).
to
eq
issu
e
.
award_emoji
.
sort_by
(
&
:id
)
expect
(
note
.
award_emoji
).
to
eq
not
e
.
award_emoji
.
sort_by
(
&
:id
)
end
end
describe
"#grouped_awards"
do
context
'default award emojis'
do
let
(
:
issue_without_downvote
)
{
create
(
:issu
e
)
}
let
(
:
issu
e_with_downvote
)
do
issue_with_downvote
=
create
(
:issu
e
)
create
(
:award_emoji
,
:downvote
,
awardable:
issu
e_with_downvote
)
issu
e_with_downvote
let
(
:
note_without_downvote
)
{
create
(
:not
e
)
}
let
(
:
not
e_with_downvote
)
do
note_with_downvote
=
create
(
:not
e
)
create
(
:award_emoji
,
:downvote
,
awardable:
not
e_with_downvote
)
not
e_with_downvote
end
it
"includes unused thumbs buttons by default"
do
expect
(
issu
e_without_downvote
.
grouped_awards
.
keys
.
sort
).
to
eq
%w(thumbsdown thumbsup)
expect
(
not
e_without_downvote
.
grouped_awards
.
keys
.
sort
).
to
eq
%w(thumbsdown thumbsup)
end
it
"doesn't include unused thumbs buttons when disabled in project"
do
issu
e_without_downvote
.
project
.
show_default_award_emojis
=
false
not
e_without_downvote
.
project
.
show_default_award_emojis
=
false
expect
(
issu
e_without_downvote
.
grouped_awards
.
keys
.
sort
).
to
be_empty
expect
(
not
e_without_downvote
.
grouped_awards
.
keys
.
sort
).
to
be_empty
end
it
"includes unused thumbs buttons when enabled in project"
do
issu
e_without_downvote
.
project
.
show_default_award_emojis
=
true
not
e_without_downvote
.
project
.
show_default_award_emojis
=
true
expect
(
issu
e_without_downvote
.
grouped_awards
.
keys
.
sort
).
to
eq
%w(thumbsdown thumbsup)
expect
(
not
e_without_downvote
.
grouped_awards
.
keys
.
sort
).
to
eq
%w(thumbsdown thumbsup)
end
it
"doesn't include unused thumbs buttons in summary"
do
expect
(
issu
e_without_downvote
.
grouped_awards
(
with_thumbs:
false
).
keys
).
to
be_empty
expect
(
not
e_without_downvote
.
grouped_awards
(
with_thumbs:
false
).
keys
).
to
be_empty
end
it
"includes used thumbs buttons when disabled in project"
do
issu
e_with_downvote
.
project
.
show_default_award_emojis
=
false
not
e_with_downvote
.
project
.
show_default_award_emojis
=
false
expect
(
issu
e_with_downvote
.
grouped_awards
.
keys
).
to
eq
%w(thumbsdown)
expect
(
not
e_with_downvote
.
grouped_awards
.
keys
).
to
eq
%w(thumbsdown)
end
it
"includes used thumbs buttons in summary"
do
expect
(
issu
e_with_downvote
.
grouped_awards
(
with_thumbs:
false
).
keys
).
to
eq
%w(thumbsdown)
expect
(
not
e_with_downvote
.
grouped_awards
(
with_thumbs:
false
).
keys
).
to
eq
%w(thumbsdown)
end
end
end
...
...
spec/models/issue_spec.rb
View file @
e87edb6b
...
...
@@ -128,6 +128,24 @@ RSpec.describe Issue do
end
end
context
'order by upvotes'
do
let!
(
:issue
)
{
create
(
:issue
)
}
let!
(
:issue2
)
{
create
(
:issue
)
}
let!
(
:award_emoji
)
{
create
(
:award_emoji
,
:upvote
,
awardable:
issue2
)
}
describe
'.order_upvotes_desc'
do
it
'orders on upvotes'
do
expect
(
described_class
.
order_upvotes_desc
.
to_a
).
to
eq
[
issue2
,
issue
]
end
end
describe
'.order_upvotes_asc'
do
it
'orders on upvotes'
do
expect
(
described_class
.
order_upvotes_asc
.
to_a
).
to
eq
[
issue
,
issue2
]
end
end
end
describe
'.with_alert_management_alerts'
do
subject
{
described_class
.
with_alert_management_alerts
}
...
...
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