From 58435c82e4aca27889b2bcfe3dbf91f6800a8a66 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Tue, 31 Jan 2012 15:59:39 +0100 Subject: [PATCH] [#775] Remove noisy journals on Attachments and Messages --- ...142400_remove_noisy_attachment_journals.rb | 30 +++++++++++++++++ ...131142401_remove_noisy_message_journals.rb | 32 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 db/migrate/20120131142400_remove_noisy_attachment_journals.rb create mode 100644 db/migrate/20120131142401_remove_noisy_message_journals.rb diff --git a/db/migrate/20120131142400_remove_noisy_attachment_journals.rb b/db/migrate/20120131142400_remove_noisy_attachment_journals.rb new file mode 100644 index 00000000..aac68296 --- /dev/null +++ b/db/migrate/20120131142400_remove_noisy_attachment_journals.rb @@ -0,0 +1,30 @@ +#-- encoding: UTF-8 +#-- copyright +# ChiliProject is a project management system. +# +# Copyright (C) 2010-2012 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +class RemoveNoisyAttachmentJournals < ActiveRecord::Migration + def self.up + AttachmentJournal.find_each(:batch_size => 100 ) do |j| + if j.changes.keys == ["downloads"] + j.destroy + elsif j.changes.keys.include? "downloads" + j.changes.delete("downloads") + j.save! + end + end + end + + def self.down + # no-op as the downloads counter shouldn't be journaled in the first time + end +end diff --git a/db/migrate/20120131142401_remove_noisy_message_journals.rb b/db/migrate/20120131142401_remove_noisy_message_journals.rb new file mode 100644 index 00000000..9b7d5d2d --- /dev/null +++ b/db/migrate/20120131142401_remove_noisy_message_journals.rb @@ -0,0 +1,32 @@ +#-- encoding: UTF-8 +#-- copyright +# ChiliProject is a project management system. +# +# Copyright (C) 2010-2012 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +class RemoveNoisyMessageJournals < ActiveRecord::Migration + def self.up + noisy_keys = %w[last_reply_id replies_count] + + MessageJournal.find_each(:batch_size => 100 ) do |j| + if (j.changes.keys | noisy_keys).sort == noisy_keys + j.destroy + elsif (j.changes.keys & noisy_keys).count > 0 + noisy_keys.each{ |k| j.changes.delete(k) } + j.save! + end + end + end + + def self.down + # no-op as the pointers shouldn't be journaled in the first time + end +end