From a0ceb9b11c4564afb9ec7accc1c4373fdc1b9718 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 13 Jan 2016 12:53:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=BA=E9=99=B7=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E7=BB=9F=E8=AE=A1=20=E9=A1=B9=E7=9B=AE=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=BA=93=E6=8F=90=E4=BA=A4=E6=AC=A1=E6=95=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 20 +++++++++++++++++-- .../20160111071411_static_project_issues.rb | 6 ++++-- ...113023045_add_journals_count_to_project.rb | 5 +++++ .../20160113023137_statics_issue_journal.rb | 12 +++++++++++ ...160113024927_statics_repository_commits.rb | 19 ++++++++++++++++++ db/schema.rb | 3 ++- 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20160113023045_add_journals_count_to_project.rb create mode 100644 db/migrate/20160113023137_statics_issue_journal.rb create mode 100644 db/migrate/20160113024927_statics_repository_commits.rb diff --git a/app/models/journal.rb b/app/models/journal.rb index e1464a703..62f0d1d69 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -48,14 +48,14 @@ class Journal < ActiveRecord::Base :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + "(#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} - before_create :split_private_notes + before_create :split_private_notes, :add_journals_count # fq after_save :act_as_activity,:be_user_score, :act_as_forge_message, :act_as_at_message # end #after_destroy :down_user_score #before_save :be_user_score - after_destroy :down_user_score + after_destroy :down_user_score, :decrease_issues_journal_count scope :visible, lambda {|*args| user = args.shift || User.current @@ -214,4 +214,20 @@ class Journal < ActiveRecord::Base end end + + # 减少留言数量统计 + def decrease_issues_journal_count + unless self.issue.project.nil? + project = self.issue.project + project.update_attribute(:journals_count, project.journals_count - 1) + end + end + + # issue留言总数更新 + def add_journals_count + unless self.issue.project.nil? && self.journalized_type == "Issue" + project = self.issue.project + project.update_attribute(:journals_count, project.journals_count + 1) + end + end end diff --git a/db/migrate/20160111071411_static_project_issues.rb b/db/migrate/20160111071411_static_project_issues.rb index d9a3a24ff..96c6d7acb 100644 --- a/db/migrate/20160111071411_static_project_issues.rb +++ b/db/migrate/20160111071411_static_project_issues.rb @@ -1,8 +1,10 @@ class StaticProjectIssues < ActiveRecord::Migration def up Project.all.each do |project| - issues_count = project.issues.count - project.update_attribute(:issues_count, issues_count) + unless project.issues.nil? + issues_count = project.issues.count + project.update_attribute(:issues_count, issues_count) + end end end diff --git a/db/migrate/20160113023045_add_journals_count_to_project.rb b/db/migrate/20160113023045_add_journals_count_to_project.rb new file mode 100644 index 000000000..9548f49c4 --- /dev/null +++ b/db/migrate/20160113023045_add_journals_count_to_project.rb @@ -0,0 +1,5 @@ +class AddJournalsCountToProject < ActiveRecord::Migration + def change + add_column :projects, :journals_count, :integer, :default => false + end +end diff --git a/db/migrate/20160113023137_statics_issue_journal.rb b/db/migrate/20160113023137_statics_issue_journal.rb new file mode 100644 index 000000000..ef54c04be --- /dev/null +++ b/db/migrate/20160113023137_statics_issue_journal.rb @@ -0,0 +1,12 @@ +class StaticsIssueJournal < ActiveRecord::Migration + def up + Project.all.each do |project| + if !project.project_score.nil? && !project.project_score.issue_journal_num.nil? + project.update_attribute(:journals_count, project.project_score.issue_journal_num) + end + end + end + + def down + end +end diff --git a/db/migrate/20160113024927_statics_repository_commits.rb b/db/migrate/20160113024927_statics_repository_commits.rb new file mode 100644 index 000000000..66fa896af --- /dev/null +++ b/db/migrate/20160113024927_statics_repository_commits.rb @@ -0,0 +1,19 @@ +class StaticsRepositoryCommits < ActiveRecord::Migration + def up + g = Gitlab.client + Project.all.each do |project| + unless project.gpid.nil? + begin + puts project.id + count = g.project(project.gpid).commit_count + rescue + logger.error("The project's rep is not exit!") + end + project.update_attribute(:commits_count, count) + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 6197c2c76..0009b881e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160111080914) do +ActiveRecord::Schema.define(:version => 20160113023137) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1416,6 +1416,7 @@ ActiveRecord::Schema.define(:version => 20160111080914) do t.integer "boards_count", :default => 0 t.integer "news_count", :default => 0 t.integer "acts_count", :default => 0 + t.integer "journals_count", :default => 0 end add_index "projects", ["lft"], :name => "index_projects_on_lft"