]> git.cworth.org Git - sup/commitdiff
return sources in id-order, with non-archived sources first
authorGrant Hollingworth <grant@antiflux.org>
Fri, 18 Jan 2008 17:06:49 +0000 (12:06 -0500)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Sun, 3 Feb 2008 00:54:21 +0000 (16:54 -0800)
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

index cf2ac6dba1ddb4694415795573612a839e8df291..e6e91984332a24cf0a281f3ad8646a24c6a3008d 100644 (file)
@@ -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