Subject: [sup-talk] Odd bug with lazy-loaded messages

From: [email-masked] (Edward Z. Yang)
Date: Mon, 27 Jul 2009 13:36:10 -0400

I've been experiencing an odd bug with the following patch
for lazy loading messages:

--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -103,7 +103,6 @@ EOS
         t.each_with_index do |(m, *o), i|
           next unless m
           BufferManager.say "#{message} (#{i}/#{num})", sid if t.size > 1
-          m.load_from_source! 
         end
       end

Specifically, the "default" opened message when I open a thread
gets a weird misrendering of the headers that looks like:

To: foo
    foo <foo at example.com>
    foo

And so forth, for all lines in To and Cc.

Any ideas what could be causing this?  I checked load_from_source! in message.rb
but didn't see anything obvious that would prevent this behavior.

Cheers,
Edward

---

From: [email-masked] (William Morgan)
Date: Mon, 03 Aug 2009 10:18:50 -0700

Sorry I didn't respond to this earlier.

> And so forth, for all lines in To and Cc.

This is because we store a couple variants of the address in the index
(e.g. the email address to the left of the @), so that a search on any
of them will bring up the message. Without #load_from_source!, the
message is loaded from the index, so it reflects those fields. So it's
basically a hack at this point. You could further hack it by undoing
that transformation. Or we could add the original version of the fields
to the index in a separate, non-searchable field, incurring the
associated storage penalties.
-- 
William <wmorgan-sup at masanjin.net>

---

From: [email-masked] (Edward Z. Yang)
Date: Sat, 08 Aug 2009 02:07:22 -0400

> associated storage penalties.

Great.  I sprinkled a few extra load_from_source! calls and I think
I made the weird behavior go away.  It's kind of sketchy though.

>From 6c539b9c0fb952b0cc10c121cb906b1aefd58c31 Mon Sep 17 00:00:00 2001
From: Edward Z. Yang <edwardzyang at thewritingpot.com>
Date: Mon, 8 Jun 2009 22:21:01 -0400
Subject: [PATCH 1/3] Remove message pre-loading; optimizes for the common case.

There are some load_from_source! calls to flush away extra
header info that we don't want displayed.  We may need to add
this in more/less places.

Signed-off-by: Edward Z. Yang <ezyang at mit.edu>
---
 lib/sup/modes/thread-index-mode.rb |    1 -
 lib/sup/modes/thread-view-mode.rb  |    2 ++
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index b671119..5e58072 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -105,7 +105,6 @@ EOS
         t.each_with_index do |(m, *o), i|
           next unless m
           BufferManager.say "#{message} (#{i}/#{num})", sid if t.size > 1
-          m.load_from_source! 
         end
       end
       mode = ThreadViewMode.new t, @hidden_labels, self
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
index 737f6f1..94e3ed7 100644
--- a/lib/sup/modes/thread-view-mode.rb
+++ b/lib/sup/modes/thread-view-mode.rb
@@ -124,6 +124,7 @@ EOS
       end
     end
 
+    latest.load_from_source!
     @layout[latest].state = :open if @layout[latest].state == :closed
     @layout[earliest].state = :detailed if earliest.has_label?(:unread) || @thread.size == 1
 
@@ -555,6 +556,7 @@ private
 
   def initial_state_for m
     if m.has_label?(:starred) || m.has_label?(:unread)
+      m.load_from_source!
       :open
     else
       :closed
-- 
1.6.3.3

---

From: [email-masked] (Edward Z. Yang)
Date: Sun, 09 Aug 2009 04:40:33 -0400

> I made the weird behavior go away.  It's kind of sketchy though.

It looks like it's still a problem in some sporadic cases.  Going to
submit a more thorough patch soon.

Cheers,
Edward