Commit ca215e66 authored by manojmj's avatar manojmj

Add Project, User, Group count to API

parent d0e21651
......@@ -28,6 +28,9 @@ Example response:
"snippets": "50",
"ssh_keys": "10",
"milestones": "40",
"users": "50",
"groups": "10",
"projects": "20",
"active_users": "50"
}
```
......@@ -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
......
......@@ -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
......
......@@ -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" }
}
}
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment