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
ca215e66
Commit
ca215e66
authored
Sep 02, 2019
by
manojmj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Project, User, Group count to API
parent
d0e21651
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
2 deletions
+27
-2
doc/api/statistics.md
doc/api/statistics.md
+3
-0
lib/api/entities.rb
lib/api/entities.rb
+12
-0
lib/api/statistics.rb
lib/api/statistics.rb
+1
-1
spec/fixtures/api/schemas/statistics.json
spec/fixtures/api/schemas/statistics.json
+6
-0
spec/requests/api/statistics_spec.rb
spec/requests/api/statistics_spec.rb
+5
-1
No files found.
doc/api/statistics.md
View file @
ca215e66
...
...
@@ -28,6 +28,9 @@ Example response:
"snippets"
:
"50"
,
"ssh_keys"
:
"10"
,
"milestones"
:
"40"
,
"users"
:
"50"
,
"groups"
:
"10"
,
"projects"
:
"20"
,
"active_users"
:
"50"
}
```
lib/api/entities.rb
View file @
ca215e66
...
...
@@ -1199,6 +1199,18 @@ module API
approximate_count_with_delimiters
(
counts
,
::
Milestone
)
end
expose
:users
do
|
counts
|
approximate_count_with_delimiters
(
counts
,
::
User
)
end
expose
:projects
do
|
counts
|
approximate_count_with_delimiters
(
counts
,
::
Project
)
end
expose
:groups
do
|
counts
|
approximate_count_with_delimiters
(
counts
,
::
Group
)
end
expose
:active_users
do
|
_
|
number_with_delimiter
(
::
User
.
active
.
count
)
end
...
...
lib/api/statistics.rb
View file @
ca215e66
...
...
@@ -4,7 +4,7 @@ module API
class
Statistics
<
Grape
::
API
before
{
authenticated_as_admin!
}
COUNTED_ITEMS
=
[
ForkNetworkMember
,
ForkNetwork
,
Issue
,
COUNTED_ITEMS
=
[
Project
,
User
,
Group
,
ForkNetworkMember
,
ForkNetwork
,
Issue
,
MergeRequest
,
Note
,
Snippet
,
Key
,
Milestone
].
freeze
desc
'Get the current application statistics'
do
...
...
spec/fixtures/api/schemas/statistics.json
View file @
ca215e66
...
...
@@ -8,6 +8,9 @@
"snippets"
,
"ssh_keys"
,
"milestones"
,
"users"
,
"projects"
,
"groups"
,
"active_users"
],
"properties"
:
{
...
...
@@ -18,6 +21,9 @@
"snippets'"
:
{
"type"
:
"string"
},
"ssh_keys'"
:
{
"type"
:
"string"
},
"milestones'"
:
{
"type"
:
"string"
},
"users'"
:
{
"type"
:
"string"
},
"projects'"
:
{
"type"
:
"string"
},
"groups'"
:
{
"type"
:
"string"
},
"active_users'"
:
{
"type"
:
"string"
}
}
}
spec/requests/api/statistics_spec.rb
View file @
ca215e66
...
...
@@ -4,6 +4,7 @@ require 'spec_helper'
describe
API
::
Statistics
,
'Statistics'
do
include
ProjectForksHelper
TABLES_TO_ANALYZE
=
%w[projects users namespaces issues merge_requests notes snippets fork_networks fork_network_members keys milestones]
.
freeze
let
(
:path
)
{
"/application/statistics"
}
...
...
@@ -49,7 +50,7 @@ describe API::Statistics, 'Statistics' do
# Make sure the reltuples have been updated
# to get a correct count on postgresql
%w[issues merge_requests notes snippets fork_networks fork_network_members keys milestones users]
.
each
do
|
table
|
TABLES_TO_ANALYZE
.
each
do
|
table
|
ActiveRecord
::
Base
.
connection
.
execute
(
"ANALYZE
#{
table
}
"
)
end
...
...
@@ -62,6 +63,9 @@ describe API::Statistics, 'Statistics' do
expect
(
json_response
[
'forks'
]).
to
eq
(
'1'
)
expect
(
json_response
[
'ssh_keys'
]).
to
eq
(
'1'
)
expect
(
json_response
[
'milestones'
]).
to
eq
(
'3'
)
expect
(
json_response
[
'users'
]).
to
eq
(
'1'
)
expect
(
json_response
[
'projects'
]).
to
eq
(
'5'
)
# projects + forks
expect
(
json_response
[
'groups'
]).
to
eq
(
'1'
)
expect
(
json_response
[
'active_users'
]).
to
eq
(
'1'
)
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