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
8aa2681f
Commit
8aa2681f
authored
Aug 05, 2021
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache commit stats for a single commit
Changelog: performance
parent
c050df26
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
11 deletions
+43
-11
lib/gitlab/git/commit_stats.rb
lib/gitlab/git/commit_stats.rb
+13
-11
spec/lib/gitlab/git/commit_stats_spec.rb
spec/lib/gitlab/git/commit_stats_spec.rb
+30
-0
No files found.
lib/gitlab/git/commit_stats.rb
View file @
8aa2681f
...
...
@@ -14,21 +14,23 @@ module Gitlab
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323
def
initialize
(
repo
,
commit
)
@id
=
commit
.
id
@additions
=
0
@deletions
=
0
@total
=
0
wrapped_gitaly_errors
do
gitaly_stats
(
repo
,
commit
)
end
end
additions
,
deletions
=
fetch_stats
(
repo
,
commit
)
def
gitaly_stats
(
repo
,
commit
)
stats
=
repo
.
gitaly_commit_client
.
commit_stats
(
@id
)
@additions
=
stats
.
additions
@deletions
=
stats
.
deletions
@additions
=
additions
.
to_i
@deletions
=
deletions
.
to_i
@total
=
@additions
+
@deletions
end
def
fetch_stats
(
repo
,
commit
)
Rails
.
cache
.
fetch
(
"commit_stats:
#{
repo
.
gl_project_path
}
:
#{
@id
}
"
)
do
stats
=
wrapped_gitaly_errors
do
repo
.
gitaly_commit_client
.
commit_stats
(
@id
)
end
[
stats
.
additions
,
stats
.
deletions
]
end
end
end
end
end
spec/lib/gitlab/git/commit_stats_spec.rb
0 → 100644
View file @
8aa2681f
# frozen_string_literal: true
require
"spec_helper"
RSpec
.
describe
Gitlab
::
Git
::
CommitStats
,
:seed_helper
do
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
,
''
,
'group/project'
)
}
let
(
:commit
)
{
Gitlab
::
Git
::
Commit
.
find
(
repository
,
SeedRepo
::
Commit
::
ID
)
}
def
verify_stats!
stats
=
described_class
.
new
(
repository
,
commit
)
expect
(
stats
).
to
have_attributes
(
additions:
eq
(
11
),
deletions:
eq
(
6
),
total:
eq
(
17
)
)
end
it
'returns commit stats and caches them'
,
:use_clean_rails_redis_caching
do
expect
(
repository
.
gitaly_commit_client
).
to
receive
(
:commit_stats
).
with
(
commit
.
id
).
and_call_original
verify_stats!
expect
(
Rails
.
cache
.
fetch
(
"commit_stats:group/project:
#{
commit
.
id
}
"
)).
to
eq
([
11
,
6
])
expect
(
repository
.
gitaly_commit_client
).
not_to
receive
(
:commit_stats
)
verify_stats!
end
end
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