add: platform statistic
This commit is contained in:
parent
ef6f2c7b42
commit
b81d92af46
|
@ -16,6 +16,7 @@ class AccountsController < ApplicationController
|
|||
ActiveRecord::Base.transaction do
|
||||
result = autologin_register(username, email, password, platform)
|
||||
if result[:message].blank?
|
||||
PlatformStatistic.data.increment!(:users_count)
|
||||
render_ok({user: result[:user]})
|
||||
else
|
||||
render_error(result[:message])
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class PlatformStatisticsController < ApplicationController
|
||||
|
||||
def index
|
||||
@platform_statistic = PlatformStatistic.data
|
||||
@project_statistic = ProjectStatistic.data
|
||||
@platform_statistic.increment!(:visits)
|
||||
@tasks_count = ActiveRecord::Base.connection.exec_query("SELECT COUNT(*) FROM tasks").rows[0][0]
|
||||
@memos_count = ActiveRecord::Base.connection.exec_query("SELECT COUNT(*) FROM memos").rows[0][0]
|
||||
end
|
||||
end
|
|
@ -8,6 +8,7 @@ class ProjectsController < ApplicationController
|
|||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||
|
||||
def index
|
||||
PlatformStatistic.data.increment!(:visits)
|
||||
scope = Projects::ListQuery.call(params)
|
||||
|
||||
# @projects = kaminari_paginate(scope)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: platform_statistics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# visits :integer default("0")
|
||||
# users_count :integer default("0")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class PlatformStatistic < ApplicationRecord
|
||||
|
||||
def self.data
|
||||
data = self.last
|
||||
if data.present?
|
||||
return data
|
||||
else
|
||||
return PlatformStatistic.create(users_count: User.count)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,4 +12,17 @@
|
|||
#
|
||||
|
||||
class ProjectStatistic < ApplicationRecord
|
||||
|
||||
def self.data
|
||||
data = self.last
|
||||
if data.present?
|
||||
return data
|
||||
else
|
||||
common_projects_count = Project.common.count
|
||||
mirror_projects_count = Project.mirror.count
|
||||
sync_mirror_projects_count = Project.sync_mirror.count
|
||||
return ProjectStatistic.create(common_projects_count: common_projects_count, mirror_projects_count: mirror_projects_count, sync_mirror_projects_count: sync_mirror_projects_count)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
json.visits @platform_statistic.visits
|
||||
json.projects_count @project_statistic.common_projects_count + @project_statistic.mirror_projects_count + @project_statistic.sync_mirror_projects_count
|
||||
json.users_count @platform_statistic.users_count
|
||||
json.tasks_count @tasks_count
|
||||
json.memos_count @memos_count
|
|
@ -102,6 +102,7 @@ Rails.application.routes.draw do
|
|||
get :template_file
|
||||
end
|
||||
end
|
||||
resources :platform_statistics, only: [:index]
|
||||
get 'home/index'
|
||||
get 'home/search'
|
||||
get 'main/first_stamp'
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class CreatePlatformStatistics < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :platform_statistics do |t|
|
||||
t.integer :visits, default: 0
|
||||
t.integer :users_count, default: 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PlatformStatistic, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue