FIX merge dev_devops branch

This commit is contained in:
Jasder 2020-10-21 11:56:30 +08:00
commit 9477555ebd
11 changed files with 66 additions and 24 deletions

View File

@ -6,12 +6,8 @@ class ProjectCategoriesController < ApplicationController
end
def group_list
# if current_user&.logged?
# projects = Project.list_user_projects(current_user.id)
# else
# projects = Project.visible
# end
projects = Project.no_anomory_projects.visible
@category_group_list = projects.joins(:project_category).group("project_categories.id", "project_categories.name").size
@project_categories = ProjectCategory.where('projects_count > 0')
# projects = Project.no_anomory_projects.visible
# @category_group_list = projects.joins(:project_category).group("project_categories.id", "project_categories.name").size
end
end

View File

@ -38,13 +38,23 @@ class ProjectsController < ApplicationController
end
def group_type_list
# if current_user&.logged?
# projects = Project.list_user_projects(current_user.id)
# else
# projects = Project.visible
# end
projects = Project.no_anomory_projects.visible
@project_group_list = projects.group(:project_type).size
project_statics = ProjectStatistic.first
@project_statics_list = [
{
project_type: 'common',
name: '开源托管项目',
projects_count: project_statics&.common_projects_count || 0
},
{
project_type: 'mirror',
name: '开源镜像项目',
projects_count: project_statics&.mirror_projects_count || 0
}
]
# projects = Project.no_anomory_projects.visible
# @project_group_list = projects.group(:project_type).size
end
def update

View File

@ -205,4 +205,14 @@ class Project < ApplicationRecord
def self.sync_educoder_shixun(url, private_token, page, per_page)
SyncEducoderShixunJob.perform_later(url, private_token, page, per_page)
end
def self.update_common_projects_count!
ps = ProjectStatistic.first
ps.increment!(:common_projects_count) unless ps.blank?
end
def self.update_mirror_projects_count!
ps = ProjectStatistic.first
ps.increment!(:mirror_projects_count) unless ps.blank?
end
end

View File

@ -0,0 +1,2 @@
class ProjectStatistic < ApplicationRecord
end

View File

@ -12,6 +12,7 @@ class Projects::CreateService < ApplicationService
@project = Project.new(project_params)
ActiveRecord::Base.transaction do
if @project.save!
Project.update_common_projects_count!
Repositories::CreateService.new(user, @project, repository_params).call
else
Rails.logger.info("#############___________create_project_erros______###########{@project.errors.messages}")

View File

@ -9,6 +9,7 @@ class Projects::MigrateService < ApplicationService
def call
@project = Project.new(project_params)
if @project.save!
Project.update_mirror_projects_count!
Repositories::MigrateService.new(user, @project, repository_params).call
else
#

View File

@ -1,5 +1,5 @@
json.array! @category_group_list do |category,v|
json.id category[0]
json.name category[1]
json.projects_count v
end
json.array! @project_categories do |category|
json.id category.id
json.name category.name
json.projects_count category.projects_count
end

View File

@ -1,5 +1,5 @@
json.array! @project_group_list do |type,v|
json.project_type type
json.name render_zh_project_type(type)
json.projects_count v
end
json.array! @project_statics_list do |static|
json.project_type static[:project_type]
json.name static[:name]
json.projects_count static[:projects_count]
end

View File

@ -0,0 +1,5 @@
class AddIndexToProjects < ActiveRecord::Migration[5.2]
def change
add_index :projects, :identifier, name: 'index_projects_on_identifier'
end
end

View File

@ -0,0 +1,12 @@
class CreateProjectStatistics < ActiveRecord::Migration[5.2]
def change
create_table :project_statistics do |t|
t.integer :common_projects_count, :default => 0
t.integer :mirror_projects_count, :default => 0
t.integer :sync_mirror_projects_count, :default => 0
t.integer :commits_total_count, :default => 0
t.timestamps
end
end
end

View File

@ -0,0 +1,5 @@
class AddIndexForProjectTypeToProjects < ActiveRecord::Migration[5.2]
def change
add_index :projects, :project_type
end
end