Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH] return sources in id-order, with non-archived sources first
@ 2008-01-18 17:06 Grant Hollingworth
  2008-01-25  5:27 ` William Morgan
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Hollingworth @ 2008-01-18 17:06 UTC (permalink / raw)


To speed up the user's view of polling, deal with sources that affect the
inbox before (for example) large mailing lists. It seemed tidier to implement
this in Index rather than PollManager.

I changed "@sources.values" to "sources" in some other methods for clarity,
which I think in this case outweighs lost efficiency.

---
 lib/sup/index.rb |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/sup/index.rb b/lib/sup/index.rb
index 1997c92..b2a1612 100644
--- a/lib/sup/index.rb
+++ b/lib/sup/index.rb
@@ -125,9 +125,13 @@ EOS
     @sources[source.id] = source
   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
+  def sources
+    ## favour the inbox by listing non-archived sources first
+    @sources.values.sort_by {|s| s.id }.partition {|s| !s.archived? }.flatten
+  end
+  
+  def source_for uri; sources.find { |s| s.is_source_for? uri }; end
+  def usual_sources; sources.find_all { |s| s.usual? }; end
 
   def load_index dir=File.join(@dir, "ferret")
     if File.exists? dir
@@ -512,7 +516,7 @@ protected
         File.chmod 0600, fn
         FileUtils.mv fn, bakfn, :force => true unless File.exists?(bakfn) && File.size(fn) == 0
       end
-      Redwood::save_yaml_obj @sources.values.sort_by { |s| s.id.to_i }, fn, true
+      Redwood::save_yaml_obj sources.sort_by { |s| s.id.to_i }, fn, true
       File.chmod 0600, fn
     end
     @sources_dirty = false
-- 
1.5.3.7


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [sup-talk] [PATCH] return sources in id-order, with non-archived sources first
  2008-01-18 17:06 [sup-talk] [PATCH] return sources in id-order, with non-archived sources first Grant Hollingworth
@ 2008-01-25  5:27 ` William Morgan
  2008-01-25 15:04   ` Grant Hollingworth
  0 siblings, 1 reply; 4+ messages in thread
From: William Morgan @ 2008-01-25  5:27 UTC (permalink / raw)


Reformatted excerpts from Grant Hollingworth's message of 2008-01-18:
> To speed up the user's view of polling, deal with sources that affect
> the inbox before (for example) large mailing lists. It seemed tidier
> to implement this in Index rather than PollManager.

Very nice. One minor comment below.

> I changed "@sources.values" to "sources" in some other methods for
> clarity, which I think in this case outweighs lost efficiency.

Sounds good. And efficiency is the least of our concerns!

> +  def sources
> +    ## favour the inbox by listing non-archived sources first
> +    @sources.values.sort_by {|s| s.id }.partition {|s| !s.archived? }.flatten
> +  end

Why bother sorting by id at all? Why not just something like:
  @sources.values.sort_by { |s| s.archived? ? 0 : 1 }


-- 
William <wmorgan-sup at masanjin.net>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [sup-talk] [PATCH] return sources in id-order, with non-archived sources first
  2008-01-25  5:27 ` William Morgan
@ 2008-01-25 15:04   ` Grant Hollingworth
  2008-02-03  0:58     ` William Morgan
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Hollingworth @ 2008-01-25 15:04 UTC (permalink / raw)


* William Morgan [Fri Jan 25 00:27:14 -0500 2008]:
> > +  def sources
> > +    ## favour the inbox by listing non-archived sources first
> > +    @sources.values.sort_by {|s| s.id }.partition {|s| !s.archived? }.flatten
> > +  end
> 
> Why bother sorting by id at all? Why not just something like:
>   @sources.values.sort_by { |s| s.archived? ? 0 : 1 }

I probably did that because it's likely that an inbox is the first source.
It's not really necessary. I think partition is clearer than sort_by in this
case.

How about changing @sources to an array?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [sup-talk] [PATCH] return sources in id-order, with non-archived sources first
  2008-01-25 15:04   ` Grant Hollingworth
@ 2008-02-03  0:58     ` William Morgan
  0 siblings, 0 replies; 4+ messages in thread
From: William Morgan @ 2008-02-03  0:58 UTC (permalink / raw)


Reformatted excerpts from Grant Hollingworth's message of 2008-01-25:
> How about changing @sources to an array?

The id is important (it's stored directly in the index), so I don't want 
removing a source to change the id of all following sources.

I've merged this into next.

-- 
William <wmorgan-sup at masanjin.net>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-03  0:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-18 17:06 [sup-talk] [PATCH] return sources in id-order, with non-archived sources first Grant Hollingworth
2008-01-25  5:27 ` William Morgan
2008-01-25 15:04   ` Grant Hollingworth
2008-02-03  0:58     ` William Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox