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
91bf332a
Commit
91bf332a
authored
Aug 01, 2021
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache content_sha256 field for Files API
Changelog: performance
parent
a3a0c0ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
lib/api/files.rb
lib/api/files.rb
+12
-3
spec/requests/api/files_spec.rb
spec/requests/api/files_spec.rb
+13
-0
No files found.
lib/api/files.rb
View file @
91bf332a
...
...
@@ -35,10 +35,9 @@ module API
not_found!
(
'Commit'
)
unless
@commit
@repo
=
user_project
.
repository
@blob
=
@repo
.
blob_at
(
@commit
.
sha
,
params
[
:file_path
])
@blob
=
@repo
.
blob_at
(
@commit
.
sha
,
params
[
:file_path
]
,
limit:
Gitlab
::
Git
::
Blob
::
LFS_POINTER_MAX_SIZE
)
not_found!
(
'File'
)
unless
@blob
@blob
.
load_all_data!
end
def
commit_response
(
attrs
)
...
...
@@ -48,13 +47,21 @@ module API
}
end
def
content_sha
Rails
.
cache
.
fetch
(
"blob_content_sha256:
#{
user_project
.
full_path
}
:
#{
@blob
.
id
}
"
)
do
@blob
.
load_all_data!
Digest
::
SHA256
.
hexdigest
(
@blob
.
data
)
end
end
def
blob_data
{
file_name:
@blob
.
name
,
file_path:
@blob
.
path
,
size:
@blob
.
size
,
encoding:
"base64"
,
content_sha256:
Digest
::
SHA256
.
hexdigest
(
@blob
.
data
)
,
content_sha256:
content_sha
,
ref:
params
[
:ref
],
blob_id:
@blob
.
id
,
commit_id:
@commit
.
id
,
...
...
@@ -154,6 +161,8 @@ module API
get
":id/repository/files/:file_path"
,
requirements:
FILE_ENDPOINT_REQUIREMENTS
do
assign_file_vars!
@blob
.
load_all_data!
data
=
blob_data
set_http_headers
(
data
)
...
...
spec/requests/api/files_spec.rb
View file @
91bf332a
...
...
@@ -95,6 +95,19 @@ RSpec.describe API::Files do
expect
(
response
.
headers
[
'X-Gitlab-Content-Sha256'
]).
to
eq
(
'c440cd09bae50c4632cc58638ad33c6aa375b6109d811e76a9cc3a613c1e8887'
)
end
it
'caches sha256 of the content'
,
:use_clean_rails_redis_caching
do
head
api
(
route
(
file_path
),
current_user
,
**
options
),
params:
params
expect
(
Rails
.
cache
.
fetch
(
"blob_content_sha256:
#{
project
.
full_path
}
:
#{
response
.
headers
[
'X-Gitlab-Blob-Id'
]
}
"
))
.
to
eq
(
'c440cd09bae50c4632cc58638ad33c6aa375b6109d811e76a9cc3a613c1e8887'
)
expect_next_instance_of
(
Gitlab
::
Git
::
Blob
)
do
|
instance
|
expect
(
instance
).
not_to
receive
(
:load_all_data!
)
end
head
api
(
route
(
file_path
),
current_user
,
**
options
),
params:
params
end
it
'returns file by commit sha'
do
# This file is deleted on HEAD
file_path
=
"files%2Fjs%2Fcommit%2Ejs%2Ecoffee"
...
...
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