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
9449b5eb
Commit
9449b5eb
authored
Nov 22, 2019
by
Alex Pooley
Committed by
Ash McKenzie
Nov 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve performance of public snippets API endpoint
parent
9fbc9e69
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
5 deletions
+32
-5
changelogs/unreleased/ap-35389-api-snippets-public-personal.yml
...logs/unreleased/ap-35389-api-snippets-public-personal.yml
+6
-0
db/migrate/20191119023952_add_created_at_index_to_snippets.rb
...igrate/20191119023952_add_created_at_index_to_snippets.rb
+17
-0
db/schema.rb
db/schema.rb
+2
-1
lib/api/snippets.rb
lib/api/snippets.rb
+2
-2
spec/requests/api/snippets_spec.rb
spec/requests/api/snippets_spec.rb
+5
-2
No files found.
changelogs/unreleased/ap-35389-api-snippets-public-personal.yml
0 → 100644
View file @
9449b5eb
---
title
:
Improve performance of /api/:version/snippets/public API and only return public
personal snippets
merge_request
:
20339
author
:
type
:
performance
db/migrate/20191119023952_add_created_at_index_to_snippets.rb
0 → 100644
View file @
9449b5eb
# frozen_string_literal: true
class
AddCreatedAtIndexToSnippets
<
ActiveRecord
::
Migration
[
5.2
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:snippets
,
:created_at
end
def
down
remove_concurrent_index
:snippets
,
:created_at
end
end
db/schema.rb
View file @
9449b5eb
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2019_11_1
8_18272
2
)
do
ActiveRecord
::
Schema
.
define
(
version:
2019_11_1
9_02395
2
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"pg_trgm"
...
...
@@ -3628,6 +3628,7 @@ ActiveRecord::Schema.define(version: 2019_11_18_182722) do
t
.
boolean
"secret"
,
default:
false
,
null:
false
t
.
index
[
"author_id"
],
name:
"index_snippets_on_author_id"
t
.
index
[
"content"
],
name:
"index_snippets_on_content_trigram"
,
opclass: :gin_trgm_ops
,
using: :gin
t
.
index
[
"created_at"
],
name:
"index_snippets_on_created_at"
t
.
index
[
"file_name"
],
name:
"index_snippets_on_file_name_trigram"
,
opclass: :gin_trgm_ops
,
using: :gin
t
.
index
[
"project_id"
,
"visibility_level"
],
name:
"index_snippets_on_project_id_and_visibility_level"
t
.
index
[
"title"
],
name:
"index_snippets_on_title_trigram"
,
opclass: :gin_trgm_ops
,
using: :gin
...
...
lib/api/snippets.rb
View file @
9449b5eb
...
...
@@ -14,7 +14,7 @@ module API
end
def
public_snippets
Snippet
sFinder
.
new
(
current_user
,
scope: :are_public
).
execute
Snippet
.
only_personal_snippets
.
are_public
.
fresh
end
def
snippets
...
...
@@ -33,7 +33,7 @@ module API
present
paginate
(
snippets_for_current_user
),
with:
Entities
::
PersonalSnippet
end
desc
'List all public snippets current_user has access to'
do
desc
'List all public
personal
snippets current_user has access to'
do
detail
'This feature was introduced in GitLab 8.15.'
success
Entities
::
PersonalSnippet
end
...
...
spec/requests/api/snippets_spec.rb
View file @
9449b5eb
...
...
@@ -66,6 +66,9 @@ describe API::Snippets do
let!
(
:public_snippet_other
)
{
create
(
:personal_snippet
,
:public
,
author:
other_user
)
}
let!
(
:private_snippet_other
)
{
create
(
:personal_snippet
,
:private
,
author:
other_user
)
}
let!
(
:internal_snippet_other
)
{
create
(
:personal_snippet
,
:internal
,
author:
other_user
)
}
let!
(
:public_snippet_project
)
{
create
(
:project_snippet
,
:public
,
author:
user
)
}
let!
(
:private_snippet_project
)
{
create
(
:project_snippet
,
:private
,
author:
user
)
}
let!
(
:internal_snippet_project
)
{
create
(
:project_snippet
,
:internal
,
author:
user
)
}
it
'returns all snippets with public visibility from all users'
do
get
api
(
"/snippets/public"
,
user
)
...
...
@@ -76,10 +79,10 @@ describe API::Snippets do
expect
(
json_response
.
map
{
|
snippet
|
snippet
[
'id'
]}
).
to
contain_exactly
(
public_snippet
.
id
,
public_snippet_other
.
id
)
expect
(
json_response
.
map
{
|
snippet
|
snippet
[
'web_url'
]}
).
to
include
(
expect
(
json_response
.
map
{
|
snippet
|
snippet
[
'web_url'
]}
).
to
contain_exactly
(
"http://localhost/snippets/
#{
public_snippet
.
id
}
"
,
"http://localhost/snippets/
#{
public_snippet_other
.
id
}
"
)
expect
(
json_response
.
map
{
|
snippet
|
snippet
[
'raw_url'
]}
).
to
include
(
expect
(
json_response
.
map
{
|
snippet
|
snippet
[
'raw_url'
]}
).
to
contain_exactly
(
"http://localhost/snippets/
#{
public_snippet
.
id
}
/raw"
,
"http://localhost/snippets/
#{
public_snippet_other
.
id
}
/raw"
)
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