From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.90.87.14 with SMTP id k14cs1205064agb; Tue, 29 Dec 2009 17:39:25 -0800 (PST) Received: by 10.224.66.211 with SMTP id o19mr8368622qai.342.1262137164602; Tue, 29 Dec 2009 17:39:24 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 5si18748866qyk.107.2009.12.29.17.39.24; Tue, 29 Dec 2009 17:39:24 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 290DC1D78877; Tue, 29 Dec 2009 20:39:24 -0500 (EST) Received: from magnesium.club.cc.cmu.edu (MAGNESIUM.CLUB.CC.cmu.edu [128.237.157.15]) by rubyforge.org (Postfix) with ESMTP id 15D891D78862 for ; Tue, 29 Dec 2009 20:39:19 -0500 (EST) Received: (qmail 13033 invoked from network); 30 Dec 2009 01:39:19 -0000 Received: from pion.club.cc.cmu.edu (HELO localhost.localdomain) (128.237.157.88) by magnesium.club.cc.cmu.edu with SMTP; 30 Dec 2009 01:39:19 -0000 From: Rich Lane To: sup-devel@rubyforge.org Date: Tue, 29 Dec 2009 17:38:02 -0800 Message-Id: <1262137085-25928-1-git-send-email-rlane@club.cc.cmu.edu> X-Mailer: git-send-email 1.6.3.3 Subject: [sup-devel] [PATCH 1/4] factor saving out of thread/message classes X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org --- lib/sup/index.rb | 7 +++++++ lib/sup/message.rb | 5 +---- lib/sup/modes/thread-index-mode.rb | 2 +- lib/sup/thread.rb | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/sup/index.rb b/lib/sup/index.rb index ff03f19..5d8d714 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -172,6 +172,13 @@ class BaseIndex def parse_query s unimplemented end + + def save_thread t + t.each_dirty_message do |m| + update_message_state m + m.clear_dirty + end + end end index_name = ENV['SUP_INDEX'] || $config[:index] || DEFAULT_INDEX diff --git a/lib/sup/message.rb b/lib/sup/message.rb index f3ac874..76ce330 100644 --- a/lib/sup/message.rb +++ b/lib/sup/message.rb @@ -182,11 +182,8 @@ class Message ## don't tempt me. def sanitize_message_id mid; mid.gsub(/(\s|[^\000-\177])+/, "")[0..254] end - def save_state index - return unless @dirty - index.update_message_state self + def clear_dirty @dirty = false - true end def has_label? t; @labels.member? t; end diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 82f258b..c4a7d38 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -477,7 +477,7 @@ EOS BufferManager.say("Saving threads...") do |say_id| dirty_threads.each_with_index do |t, i| BufferManager.say "Saving modified thread #{i + 1} of #{dirty_threads.length}...", say_id - t.save_state Index + Index.save_thread t end end end diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb index 2300305..3fdf1f6 100644 --- a/lib/sup/thread.rb +++ b/lib/sup/thread.rb @@ -112,7 +112,7 @@ class Thread def set_labels l; each { |m, *o| m && m.labels = l }; end def has_label? t; any? { |m, *o| m && m.has_label?(t) }; end - def save_state index; each { |m, *o| m && m.save_state(index) }; end + def each_dirty_message; each { |m, *o| m && m.dirty? && yield(m) }; end def direct_participants map { |m, *o| [m.from] + m.to if m }.flatten.compact.uniq -- 1.6.3.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel