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
d0d318ff
Commit
d0d318ff
authored
Jul 17, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
fa7431cb
9c3dfd20
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
4 deletions
+26
-4
app/models/active_session.rb
app/models/active_session.rb
+8
-4
changelogs/unreleased/64315-mget_sessions_in_chunks.yml
changelogs/unreleased/64315-mget_sessions_in_chunks.yml
+5
-0
spec/models/active_session_spec.rb
spec/models/active_session_spec.rb
+13
-0
No files found.
app/models/active_session.rb
View file @
d0d318ff
...
...
@@ -3,6 +3,8 @@
class
ActiveSession
include
ActiveModel
::
Model
SESSION_BATCH_SIZE
=
200
attr_accessor
:created_at
,
:updated_at
,
:session_id
,
:ip_address
,
:browser
,
:os
,
:device_name
,
:device_type
,
...
...
@@ -106,10 +108,12 @@ class ActiveSession
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
session_keys
=
session_ids
.
map
{
|
session_id
|
"
#{
Gitlab
::
Redis
::
SharedState
::
SESSION_NAMESPACE
}
:
#{
session_id
}
"
}
redis
.
mget
(
session_keys
).
compact
.
map
do
|
raw_session
|
# rubocop:disable Security/MarshalLoad
Marshal
.
load
(
raw_session
)
# rubocop:enable Security/MarshalLoad
session_keys
.
each_slice
(
SESSION_BATCH_SIZE
).
flat_map
do
|
session_keys_batch
|
redis
.
mget
(
session_keys_batch
).
compact
.
map
do
|
raw_session
|
# rubocop:disable Security/MarshalLoad
Marshal
.
load
(
raw_session
)
# rubocop:enable Security/MarshalLoad
end
end
end
end
...
...
changelogs/unreleased/64315-mget_sessions_in_chunks.yml
0 → 100644
View file @
d0d318ff
---
title
:
Do Redis lookup in batches in ActiveSession.sessions_from_ids
merge_request
:
30561
author
:
type
:
performance
spec/models/active_session_spec.rb
View file @
d0d318ff
...
...
@@ -132,6 +132,19 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
expect
(
ActiveSession
.
sessions_from_ids
([])).
to
eq
([])
end
it
'uses redis lookup in batches'
do
stub_const
(
'ActiveSession::SESSION_BATCH_SIZE'
,
1
)
redis
=
double
(
:redis
)
expect
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis
)
sessions
=
[
'session-a'
,
'session-b'
]
mget_responses
=
sessions
.
map
{
|
session
|
[
Marshal
.
dump
(
session
)]}
expect
(
redis
).
to
receive
(
:mget
).
twice
.
and_return
(
*
mget_responses
)
expect
(
ActiveSession
.
sessions_from_ids
([
1
,
2
])).
to
eql
(
sessions
)
end
end
describe
'.set'
do
...
...
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