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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
58c5b463
Commit
58c5b463
authored
Nov 27, 2017
by
Francisco Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored /projects and /user/:user_id/projects endpoints
parent
c85f9c5b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
25 deletions
+77
-25
lib/api/entities.rb
lib/api/entities.rb
+38
-10
lib/api/groups.rb
lib/api/groups.rb
+3
-13
lib/api/projects.rb
lib/api/projects.rb
+2
-2
lib/api/projects_relation_builder.rb
lib/api/projects_relation_builder.rb
+34
-0
No files found.
lib/api/entities.rb
View file @
58c5b463
...
...
@@ -94,7 +94,13 @@ module API
project
.
avatar_url
(
only_path:
false
)
end
expose
:star_count
,
:forks_count
expose
:last_activity_at
expose
:created_at
,
:last_activity_at
def
self
.
preload_relation
(
projects_relation
)
projects_relation
.
preload
(
:project_feature
,
:route
)
.
preload
(
namespace:
[
:route
,
:owner
],
tags: :taggings
)
end
end
class
Project
<
BasicProjectDetails
...
...
@@ -128,6 +134,18 @@ module API
expose
:members
do
|
project
|
expose_url
(
api_v4_projects_members_path
(
id:
project
.
id
))
end
def
self
.
preload_relation
(
projects_relation
)
super
(
projects_relation
).
preload
(
:group
)
.
preload
(
project_group_links: :group
,
fork_network: :root_project
,
forked_project_link: :forked_from_project
,
forked_from_project:
[
:route
,
:forks
,
namespace: :route
,
tags: :taggings
])
end
def
self
.
forks_counting_projects
(
projects_relation
)
projects_relation
+
projects_relation
.
map
(
&
:forked_from_project
).
compact
end
end
expose
:archived?
,
as: :archived
...
...
@@ -635,9 +653,16 @@ module API
class
MemberAccess
<
Grape
::
Entity
expose
:access_level
expose
:notification_level
do
|
member
,
options
|
if
member
.
notification_setting
::
NotificationSetting
.
levels
[
member
.
notification_setting
.
level
]
end
notification
=
member_notification_setting
(
member
)
::
NotificationSetting
.
levels
[
notification
.
level
]
if
notification
end
private
def
member_notification_setting
(
member
)
member
.
user
.
notification_settings
.
select
do
|
notification
|
notification
.
source_id
==
member
.
source_id
&&
notification
.
source_type
==
member
.
source_type
end
.
last
end
end
...
...
@@ -680,18 +705,21 @@ module API
expose
:permissions
do
expose
:project_access
,
using:
Entities
::
ProjectAccess
do
|
project
,
options
|
if
options
.
key?
(
:project_members
)
(
options
[
:project_members
]
||
[]).
find
{
|
member
|
member
.
source_id
==
project
.
id
}
else
project
.
project_members
.
find_by
(
user_id:
options
[
:current_user
].
id
)
(
options
[
:project_members
]
||
[]).
select
{
|
member
|
member
.
source_id
==
project
.
id
}.
last
elsif
project
.
project_members
.
any?
# This is not the bet option to search in a CollectionProxy, but if
# we use find_by we will perform another query, even if the association
# is loaded
project
.
project_members
.
select
{
|
project_member
|
project_member
.
user_id
==
options
[
:current_user
].
id
}.
last
end
end
expose
:group_access
,
using:
Entities
::
GroupAccess
do
|
project
,
options
|
if
project
.
group
if
options
.
key?
(
:group_members
)
(
options
[
:group_members
]
||
[]).
find
{
|
member
|
member
.
source_id
==
project
.
namespace_id
}
els
e
project
.
group
.
group_members
.
find_by
(
user_id:
options
[
:current_user
].
id
)
(
options
[
:group_members
]
||
[]).
select
{
|
member
|
member
.
source_id
==
project
.
namespace_id
}.
last
els
if
project
.
group
.
group_members
.
any?
project
.
group
.
group_members
.
select
{
|
group_member
|
group_member
.
user_id
==
options
[
:current_user
].
id
}.
last
end
end
end
...
...
lib/api/groups.rb
View file @
58c5b463
...
...
@@ -55,19 +55,8 @@ module API
def
find_group_projects
(
params
)
group
=
find_group!
(
params
[
:id
])
projects
=
GroupProjectsFinder
.
new
(
group:
group
,
current_user:
current_user
,
params:
project_finder_params
).
execute
projects
=
projects
.
preload
(
:project_feature
,
:route
,
:group
)
.
preload
(
namespace:
[
:route
,
:owner
],
tags: :taggings
,
project_group_links: :group
,
fork_network: :root_project
,
forked_project_link: :forked_from_project
,
forked_from_project:
[
:route
,
:forks
,
namespace: :route
,
tags: :taggings
])
projects
=
reorder_projects
(
projects
)
projects
=
paginate
(
projects
)
projects_with_forks
=
projects
+
projects
.
map
(
&
:forked_from_project
).
compact
::
Projects
::
BatchForksCountService
.
new
(
projects_with_forks
).
refresh_cache
::
Projects
::
BatchOpenIssuesCountService
.
new
(
projects
).
refresh_cache
projects
paginate
(
projects
)
end
def
present_groups
(
params
,
groups
)
...
...
@@ -190,7 +179,8 @@ module API
get
":id/projects"
do
projects
=
find_group_projects
(
params
)
entity
=
params
[
:simple
]
?
Entities
::
BasicProjectDetails
:
Entities
::
Project
present
projects
,
with:
entity
,
current_user:
current_user
present
entity
.
prepare_relation
(
projects
),
with:
entity
,
current_user:
current_user
end
desc
'Get a list of subgroups in this group.'
do
...
...
lib/api/projects.rb
View file @
58c5b463
...
...
@@ -79,9 +79,9 @@ module API
projects
=
projects
.
with_statistics
if
params
[
:statistics
]
projects
=
projects
.
with_issues_enabled
if
params
[
:with_issues_enabled
]
projects
=
projects
.
with_merge_requests_enabled
if
params
[
:with_merge_requests_enabled
]
projects
=
paginate
(
projects
)
if
current_user
projects
=
projects
.
includes
(
:route
,
:taggings
,
namespace: :route
)
project_members
=
current_user
.
project_members
group_members
=
current_user
.
group_members
end
...
...
@@ -95,7 +95,7 @@ module API
)
options
[
:with
]
=
Entities
::
BasicProjectDetails
if
params
[
:simple
]
present
paginate
(
projects
),
options
present
options
[
:with
].
prepare_relation
(
projects
),
options
end
end
...
...
lib/api/projects_relation_builder.rb
0 → 100644
View file @
58c5b463
module
API
module
ProjectsRelationBuilder
extend
ActiveSupport
::
Concern
module
ClassMethods
def
prepare_relation
(
relation
)
relation
=
preload_relation
(
relation
)
execute_batch_counting
(
relation
)
relation
end
def
preload_relation
(
relation
)
raise
NotImplementedError
,
'self.preload_relation method must be defined and return a relation'
end
def
forks_counting_projects
(
projects_relation
)
projects_relation
end
def
batch_forks_counting
(
projects_relation
)
::
Projects
::
BatchForksCountService
.
new
(
forks_counting_projects
(
projects_relation
)).
refresh_cache
end
def
batch_open_issues_counting
(
projects_relation
)
::
Projects
::
BatchOpenIssuesCountService
.
new
(
projects_relation
).
refresh_cache
end
def
execute_batch_counting
(
projects_relation
)
batch_forks_counting
(
projects_relation
)
batch_open_issues_counting
(
projects_relation
)
end
end
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