Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Rich Lane <rlane@club.cc.cmu.edu>
To: sup-devel@rubyforge.org
Subject: [sup-devel] [PATCH 3/4] immediate thread indexing
Date: Tue, 29 Dec 2009 17:38:04 -0800	[thread overview]
Message-ID: <1262137085-25928-3-git-send-email-rlane@club.cc.cmu.edu> (raw)
In-Reply-To: <1262137085-25928-2-git-send-email-rlane@club.cc.cmu.edu>

---
 lib/sup/modes/inbox-mode.rb        |    4 +++
 lib/sup/modes/thread-index-mode.rb |   40 +++++++++++++----------------------
 lib/sup/modes/thread-view-mode.rb  |    7 ++++++
 3 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb
index ba095da..9220925 100644
--- a/lib/sup/modes/inbox-mode.rb
+++ b/lib/sup/modes/inbox-mode.rb
@@ -34,6 +34,7 @@ class InboxMode < ThreadIndexMode
     cursor_thread.remove_label :inbox
     hide_thread cursor_thread
     regen_text
+    Index.save_thread thread
   end
 
   def multi_archive threads
@@ -50,6 +51,7 @@ class InboxMode < ThreadIndexMode
       hide_thread t
     end
     regen_text
+    threads.each { |t| Index.save_thread t }
   end
 
   def read_and_archive
@@ -66,6 +68,7 @@ class InboxMode < ThreadIndexMode
     cursor_thread.remove_label :inbox
     hide_thread cursor_thread
     regen_text
+    Index.save_thread thread
   end
 
   def multi_read_and_archive threads
@@ -86,6 +89,7 @@ class InboxMode < ThreadIndexMode
       regen_text
     end
 
+    threads.each { |t| Index.save_thread t }
   end
 
   def handle_unarchived_update sender, m
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index f6ea27c..5393189 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -37,7 +37,6 @@ EOS
     k.add :toggle_spam, "Mark/unmark thread as spam", 'S'
     k.add :toggle_deleted, "Delete/undelete thread", 'd'
     k.add :kill, "Kill thread (never to be seen in inbox again)", '&'
-    k.add :save, "Save changes now", '$'
     k.add :jump_to_next_new, "Jump to next new thread", :tab
     k.add :reply, "Reply to latest message in a thread", 'r'
     k.add :reply_all, "Reply to all participants of the latest message in a thread", 'G'
@@ -269,12 +268,14 @@ EOS
     UndoManager.register "toggling thread starred status", undo
     update_text_for_line curpos
     cursor_down
+    Index.save_thread t
   end
 
   def multi_toggle_starred threads
     UndoManager.register "toggling #{threads.size.pluralize 'thread'} starred status",
       threads.map { |t| actually_toggle_starred t }
     regen_text
+    threads.each { |t| Index.save_thread t }
   end
 
   ## returns an undo lambda
@@ -352,12 +353,14 @@ EOS
     undo = actually_toggle_archived t
     UndoManager.register "deleting/undeleting thread #{t.first.id}", undo, lambda { update_text_for_line curpos }
     update_text_for_line curpos
+    Index.save_thread t
   end
 
   def multi_toggle_archived threads
     undos = threads.map { |t| actually_toggle_archived t }
     UndoManager.register "deleting/undeleting #{threads.size.pluralize 'thread'}", undos, lambda { regen_text }
     regen_text
+    threads.each { |t| Index.save_thread t }
   end
 
   def toggle_new
@@ -365,11 +368,13 @@ EOS
     t.toggle_label :unread
     update_text_for_line curpos
     cursor_down
+    Index.save_thread t
   end
 
   def multi_toggle_new threads
     threads.each { |t| t.toggle_label :unread }
     regen_text
+    threads.each { |t| Index.save_thread t }
   end
 
   def multi_toggle_tagged threads
@@ -385,6 +390,7 @@ EOS
 
   def multi_join_threads threads
     @ts.join_threads threads or return
+    threads.each { |t| Index.save_thread t }
     @tags.drop_all_tags # otherwise we have tag pointers to invalid threads!
     update
   end
@@ -421,6 +427,7 @@ EOS
     UndoManager.register "marking/unmarking  #{threads.size.pluralize 'thread'} as spam",
                          undos, lambda { regen_text }
     regen_text
+    threads.each { |t| Index.save_thread t }
   end
 
   def toggle_deleted
@@ -434,6 +441,7 @@ EOS
     UndoManager.register "deleting/undeleting #{threads.size.pluralize 'thread'}",
                          undos, lambda { regen_text }
     regen_text
+    threads.each { |t| Index.save_thread t }
   end
 
   def kill
@@ -458,29 +466,7 @@ EOS
 
     regen_text
     BufferManager.flash "#{threads.size.pluralize 'thread'} killed."
-  end
-
-  def save background=true
-    if background
-      Redwood::reporting_thread("saving thread") { actually_save }
-    else
-      actually_save
-    end
-  end
-
-  def actually_save
-    @save_thread_mutex.synchronize do
-      BufferManager.say("Saving contacts...") { ContactManager.instance.save }
-      dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } }
-      next if dirty_threads.empty?
-
-      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
-          Index.save_thread_async t
-        end
-      end
-    end
+    threads.each { |t| Index.save_thread t }
   end
 
   def cleanup
@@ -492,7 +478,8 @@ EOS
       sleep 0.1 # TODO: necessary?
       BufferManager.erase_flash
     end
-    save false
+    dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } }
+    fail "dirty threads remain" unless dirty_threads.empty?
     super
   end
 
@@ -546,6 +533,7 @@ EOS
     end
 
     UpdateManager.relay self, :labeled, thread.first
+    Index.save_thread thread
   end
 
   def multi_edit_labels threads
@@ -582,6 +570,8 @@ EOS
       end
       regen_text
     end
+    
+    threads.each { |t| Index.save_thread t }
   end
 
   def reply type_arg=nil
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
index 55d81b9..99abb04 100644
--- a/lib/sup/modes/thread-view-mode.rb
+++ b/lib/sup/modes/thread-view-mode.rb
@@ -131,6 +131,7 @@ EOS
     @layout[earliest].state = :detailed if earliest.has_label?(:unread) || @thread.size == 1
 
     @thread.remove_label :unread
+    Index.save_thread @thread
     regen_text
   end
 
@@ -258,6 +259,7 @@ EOS
     new_labels.each { |l| LabelManager << l }
     update
     UpdateManager.relay self, :labeled, @thread.first
+    Index.save_thread @thread
     UndoManager.register "labeling thread" do
       @thread.labels = old_labels
       UpdateManager.relay self, :labeled, @thread.first
@@ -284,6 +286,7 @@ EOS
     ## star to the display
     update
     UpdateManager.relay self, :single_message_labeled, m
+    Index.save_thread @thread
   end
 
   ## called when someone presses enter when the cursor is highlighting
@@ -478,6 +481,7 @@ EOS
     dispatch op do
       @thread.remove_label :inbox
       UpdateManager.relay self, :archived, @thread.first
+      Index.save_thread @thread
       UndoManager.register "archiving 1 thread" do
         @thread.apply_label :inbox
         UpdateManager.relay self, :unarchived, @thread.first
@@ -489,6 +493,7 @@ EOS
     dispatch op do
       @thread.apply_label :spam
       UpdateManager.relay self, :spammed, @thread.first
+      Index.save_thread @thread
       UndoManager.register "marking 1 thread as spam" do
         @thread.remove_label :spam
         UpdateManager.relay self, :unspammed, @thread.first
@@ -500,6 +505,7 @@ EOS
     dispatch op do
       @thread.apply_label :deleted
       UpdateManager.relay self, :deleted, @thread.first
+      Index.save_thread @thread
       UndoManager.register "deleting 1 thread" do
         @thread.remove_label :deleted
         UpdateManager.relay self, :undeleted, @thread.first
@@ -511,6 +517,7 @@ EOS
     dispatch op do
       @thread.apply_label :unread
       UpdateManager.relay self, :unread, @thread.first
+      Index.save_thread @thread
     end
   end
 
-- 
1.6.3.3

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


  reply	other threads:[~2009-12-30  1:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-30  1:38 [sup-devel] [PATCH 1/4] factor saving out of thread/message classes Rich Lane
2009-12-30  1:38 ` [sup-devel] [PATCH 2/4] async thread indexing Rich Lane
2009-12-30  1:38   ` Rich Lane [this message]
2009-12-30  1:38     ` [sup-devel] [PATCH 4/4] force the index sync thread to give up the cpu Rich Lane
2009-12-31 20:09 ` [sup-devel] [PATCH 1/4] factor saving out of thread/message classes William Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1262137085-25928-3-git-send-email-rlane@club.cc.cmu.edu \
    --to=rlane@club.cc.cmu.edu \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox