[#775] Remove noisy journals on Attachments and Messages

This commit is contained in:
Holger Just 2012-01-31 15:59:39 +01:00
parent 01fefe8d3b
commit 58435c82e4
2 changed files with 62 additions and 0 deletions

View File

@ -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

View File

@ -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