]> git.cworth.org Git - sup/commitdiff
disabled caching of starred and new values, because we need to do more work for
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Tue, 9 Jan 2007 00:19:08 +0000 (00:19 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Tue, 9 Jan 2007 00:19:08 +0000 (00:19 +0000)
them to actually be valid (namely, determine thread dirtiness) and because they
don't actually seem to make that much of a difference.

git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@234 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/index.rb
lib/sup/modes/thread-index-mode.rb

index 9c9766d2b1abe7f5bba44938993195654cca6c93..b328df81aea7f0cd121eeb9cf12be7189b5db799 100644 (file)
@@ -45,7 +45,7 @@ class Index
     @sources[source.id] = source
   end
 
-  def source_for name; @sources.values.find { |s| s.is_source_for? name }; end
+  def source_for uri; @sources.values.find { |s| s.is_source_for? uri }; end
   def usual_sources; @sources.values.find_all { |s| s.usual? }; end
   def sources; @sources.values; end
 
@@ -231,8 +231,8 @@ class Index
     @index.add_document d
     
     ## TODO: figure out why this is sometimes triggered
-    #docid, entry = load_entry_for_id m.id
-    #raise "just added message #{m.id} but couldn't find it in a search" unless docid
+    docid, entry = load_entry_for_id m.id
+    raise "just added message #{m.id} but couldn't find it in a search" unless docid
     true
   end
 
index 51d1d44da35acc71c1dd9876c0f8b11cbe4d99c0..f5743a169127599c11d9acac30b6641f61bf7b56 100644 (file)
@@ -1,3 +1,4 @@
+require 'thread'
 module Redwood
 
 ## subclasses should implement load_threads
@@ -105,7 +106,7 @@ class ThreadIndexMode < LineCursorMode
   end
 
   def edit_message
-    t = @threads[curpos] or return
+    return unless(t = @threads[curpos])
     message, *crap = t.find { |m, *o| m.has_label? :draft }
     if message
       mode = ResumeMode.new message
@@ -115,16 +116,19 @@ class ThreadIndexMode < LineCursorMode
     end
   end
 
-  def toggle_starred
-    t = @threads[curpos] or return
-    @starred_cache[t] = t.toggle_label :starred
+  def toggle_starred t=@threads[curpos]
+    if t.has_label? :starred # if ANY message has a star
+      t.remove_label :starred # remove from all
+    else
+      t.first.add_label :starred # add only to first
+    end
+    @starred_cache[t] = t.first.has_label? :starred
     update_text_for_line curpos
     cursor_down
   end
 
   def multi_toggle_starred threads
-    threads.each { |t| @starred_cache[t] = t.toggle_label :starred }
-    regen_text
+    threads.each { |t| toggle_starred t }
   end
 
   def toggle_archived
@@ -365,8 +369,19 @@ protected
       from += "." unless from[-1] == ?\s
     end
 
-    new = @new_cache.member?(t) ? @new_cache[t] : @new_cache[t] = t.has_label?(:unread)
-    starred = @starred_cache.member?(t) ? @starred_cache[t] : @starred_cache[t] = t.has_label?(:starred)
+
+    ## ok, turns out it's not so simple. messages can be added to the
+    ## threadset at any point, which can affect these values, so i'm
+    ## going to ignore the caches for now.
+    ##
+    ## for real caching to work we'd have to have a dirty mechanism on
+    ## the threadset.
+    
+    new = t.has_label?(:unread)
+    # new = @new_cache.member?(t) ? @new_cache[t] : @new_cache[t] = t.has_label?(:unread)
+
+    starred = t.has_label?(:starred)
+    # starred = @starred_cache.member?(t) ? @starred_cache[t] : @starred_cache[t] = t.has_label?(:starred)
 
     dp = (@dp_cache[t] ||= t.direct_participants.any? { |p| AccountManager.is_account? p })
     p = (@p_cache[t] ||= (dp || t.participants.any? { |p| AccountManager.is_account? p }))
@@ -392,6 +407,7 @@ private
 
   def initialize_threads
     @ts = ThreadSet.new Index.instance
+    @ts_mutex = Mutex.new
     @date_cache = {}
     @who_cache = {}
     @dp_cache = {}