diff --git a/app/models/project.rb b/app/models/project.rb index cd4036810..f17124478 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -155,7 +155,7 @@ class Project < ActiveRecord::Base # 创建project之后默认创建一个board,之后的board去掉了board的概念 after_create :create_board_sync,:acts_as_forge_activities,:create_project_ealasticsearch_index before_destroy :delete_all_members,:delete_project_ealasticsearch_index - after_update :update_project_ealasticsearch_index + # after_update :update_project_ealasticsearch_index def remove_references_before_destroy return if self.id.nil? Watcher.delete_all ['watchable_id = ?', id] @@ -1223,21 +1223,21 @@ class Project < ActiveRecord::Base self.__elasticsearch__.index_document end end - def update_project_ealasticsearch_index - if self.is_public #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 - begin - self.__elasticsearch__.update_document - rescue => e - self.__elasticsearch__.index_document - end - else #如果是更新成为私有的,那么索引就要被删除 - begin - self.__elasticsearch__.delete_document - rescue => e - - end - end - end + # def update_project_ealasticsearch_index + # if self.is_public #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 + # begin + # self.__elasticsearch__.update_document + # rescue => e + # self.__elasticsearch__.index_document + # end + # else #如果是更新成为私有的,那么索引就要被删除 + # begin + # self.__elasticsearch__.delete_document + # rescue => e + # + # end + # end + # end def delete_project_ealasticsearch_index begin self.__elasticsearch__.delete_document diff --git a/db/migrate/20160111071348_static_project_boards.rb b/db/migrate/20160111071348_static_project_boards.rb new file mode 100644 index 000000000..1d85860c6 --- /dev/null +++ b/db/migrate/20160111071348_static_project_boards.rb @@ -0,0 +1,19 @@ +class StaticProjectBoards < ActiveRecord::Migration + def up + begin + Project.all.each do |project| + puts project.id + unless project.boards.first.nil? + boards_count = project.boards.first.topics.count + project.update_attribute(:boards_count, boards_count) + end + end + ensure + self.down + end + end + + def down + Project.update_all(:boards_count => false) + end +end diff --git a/db/migrate/20160111071411_static_project_issues.rb b/db/migrate/20160111071411_static_project_issues.rb new file mode 100644 index 000000000..273527164 --- /dev/null +++ b/db/migrate/20160111071411_static_project_issues.rb @@ -0,0 +1,12 @@ +class StaticProjectIssues < ActiveRecord::Migration + def up + Project.all.each do |project| + issues_count = project.issues.count + project.update_attribute(:issues_count, boards_count) + end + end + + def down + Project.all.update_all(:issues_count => false) + end +end diff --git a/db/migrate/20160111071529_static_project_news.rb b/db/migrate/20160111071529_static_project_news.rb new file mode 100644 index 000000000..6ccefbc32 --- /dev/null +++ b/db/migrate/20160111071529_static_project_news.rb @@ -0,0 +1,12 @@ +class StaticProjectNews < ActiveRecord::Migration + def up + Project.all.each do |project| + news_count = project.news.count + project.update_attribute(:news_count, news_count) + end + end + + def down + Project.all.update_all(:news_count => false) + end +end diff --git a/db/migrate/20160111071558_static_project_attachments.rb b/db/migrate/20160111071558_static_project_attachments.rb new file mode 100644 index 000000000..af4a282ed --- /dev/null +++ b/db/migrate/20160111071558_static_project_attachments.rb @@ -0,0 +1,12 @@ +class StaticProjectAttachments < ActiveRecord::Migration + def up + Project.all.each do |project| + attachments_count = project.attachments.count + project.update_attribute(:attachments_count, attachments_count) + end + end + + def down + Project.all.update_all(:attachments_count => false) + end +end diff --git a/db/migrate/20160111080833_add_acts_count_to_project.rb b/db/migrate/20160111080833_add_acts_count_to_project.rb new file mode 100644 index 000000000..a990302bc --- /dev/null +++ b/db/migrate/20160111080833_add_acts_count_to_project.rb @@ -0,0 +1,5 @@ +class AddActsCountToProject < ActiveRecord::Migration + def change + add_column :projects, :acts_count, :integer, :default => false + end +end diff --git a/db/migrate/20160111080914_static_project_acts.rb b/db/migrate/20160111080914_static_project_acts.rb new file mode 100644 index 000000000..6f0d4a2e6 --- /dev/null +++ b/db/migrate/20160111080914_static_project_acts.rb @@ -0,0 +1,12 @@ +class StaticProjectActs < ActiveRecord::Migration + def up + Project.all.each do |project| + acts_count = ForgeActivity.where("project_id = ?", project.id).count + project.update_attribute(:acts_count, acts_count) + end + end + + def down + Project.all.update_all(:acts_count => false) + end +end