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
7d2859e9
Commit
7d2859e9
authored
Mar 01, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Leverage user_contributed_projects to find recent events.
Closes #40525.
parent
7e7f260d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
9 deletions
+46
-9
app/finders/user_recent_events_finder.rb
app/finders/user_recent_events_finder.rb
+38
-7
app/models/user.rb
app/models/user.rb
+3
-1
changelogs/unreleased/40525-listing-user-activity-timeouts.yml
...elogs/unreleased/40525-listing-user-activity-timeouts.yml
+5
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+0
-1
No files found.
app/finders/user_recent_events_finder.rb
View file @
7d2859e9
...
@@ -12,6 +12,8 @@ class UserRecentEventsFinder
...
@@ -12,6 +12,8 @@ class UserRecentEventsFinder
attr_reader
:current_user
,
:target_user
,
:params
attr_reader
:current_user
,
:target_user
,
:params
LIMIT
=
20
def
initialize
(
current_user
,
target_user
,
params
=
{})
def
initialize
(
current_user
,
target_user
,
params
=
{})
@current_user
=
current_user
@current_user
=
current_user
@target_user
=
target_user
@target_user
=
target_user
...
@@ -19,15 +21,44 @@ class UserRecentEventsFinder
...
@@ -19,15 +21,44 @@ class UserRecentEventsFinder
end
end
def
execute
def
execute
target_user
recent_events
(
params
[
:offset
]
||
0
)
.
recent_events
.
joins
(
:project
)
.
merge
(
projects_for_current_user
)
.
references
(
:project
)
.
with_associations
.
with_associations
.
limit_recent
(
20
,
params
[
:offset
])
.
limit_recent
(
LIMIT
,
params
[
:offset
])
end
private
def
recent_events
(
offset
)
sql
=
<<~
SQL
(
#{
projects
}
) AS projects_for_join
JOIN (
#{
target_events
.
to_sql
}
) AS
#{
Event
.
table_name
}
ON
#{
Event
.
table_name
}
.project_id = projects_for_join.id
SQL
# Workaround for https://github.com/rails/rails/issues/24193
Event
.
from
([
Arel
.
sql
(
sql
)])
end
end
def
projects_for_current_user
def
target_events
ProjectsFinder
.
new
(
current_user:
current_user
).
execute
Event
.
where
(
author:
target_user
)
end
def
projects
# Compile a list of projects `current_user` interacted with
# and `target_user` is allowed to see.
authorized
=
target_user
.
project_interactions
.
joins
(
:project_authorizations
)
.
where
(
project_authorizations:
{
user:
current_user
})
.
select
(
:id
)
visible
=
target_user
.
project_interactions
.
where
(
visibility_level:
[
Gitlab
::
VisibilityLevel
::
INTERNAL
,
Gitlab
::
VisibilityLevel
::
PUBLIC
])
.
select
(
:id
)
Gitlab
::
SQL
::
Union
.
new
([
authorized
,
visible
]).
to_sql
end
end
end
end
app/models/user.rb
View file @
7d2859e9
...
@@ -114,13 +114,15 @@ class User < ActiveRecord::Base
...
@@ -114,13 +114,15 @@ class User < ActiveRecord::Base
has_many
:project_authorizations
has_many
:project_authorizations
has_many
:authorized_projects
,
through: :project_authorizations
,
source: :project
has_many
:authorized_projects
,
through: :project_authorizations
,
source: :project
has_many
:user_interacted_projects
has_many
:project_interactions
,
through: :user_interacted_projects
,
source: :project
,
class_name:
'Project'
has_many
:snippets
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:snippets
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:notes
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:notes
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:issues
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:issues
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:events
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:events
,
dependent: :destroy
,
foreign_key: :author_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:subscriptions
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:subscriptions
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:recent_events
,
->
{
order
"id DESC"
},
foreign_key: :author_id
,
class_name:
"Event"
has_many
:oauth_applications
,
class_name:
'Doorkeeper::Application'
,
as: :owner
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:oauth_applications
,
class_name:
'Doorkeeper::Application'
,
as: :owner
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_one
:abuse_report
,
dependent: :destroy
,
foreign_key: :user_id
# rubocop:disable Cop/ActiveRecordDependent
has_one
:abuse_report
,
dependent: :destroy
,
foreign_key: :user_id
# rubocop:disable Cop/ActiveRecordDependent
has_many
:reported_abuse_reports
,
dependent: :destroy
,
foreign_key: :reporter_id
,
class_name:
"AbuseReport"
# rubocop:disable Cop/ActiveRecordDependent
has_many
:reported_abuse_reports
,
dependent: :destroy
,
foreign_key: :reporter_id
,
class_name:
"AbuseReport"
# rubocop:disable Cop/ActiveRecordDependent
...
...
changelogs/unreleased/40525-listing-user-activity-timeouts.yml
0 → 100644
View file @
7d2859e9
---
title
:
Improve database response time for user activity listing.
merge_request
:
17454
author
:
type
:
performance
spec/models/user_spec.rb
View file @
7d2859e9
...
@@ -27,7 +27,6 @@ describe User do
...
@@ -27,7 +27,6 @@ describe User do
it
{
is_expected
.
to
have_many
(
:keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:recent_events
).
class_name
(
'Event'
)
}
it
{
is_expected
.
to
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
...
...
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