Clean up Web#page_names_by_author implemention

This commit is contained in:
James Herdman 2009-08-29 15:03:48 -04:00
parent 6a4af8a59a
commit 23dae8b155

View file

@ -82,18 +82,19 @@ class Web < ActiveRecord::Base
self[:markup].to_sym self[:markup].to_sym
end end
# @return [Hash] a Hash wherein the key is some author's name, and the
# values are an array of page names for that author.
def page_names_by_author def page_names_by_author
connection.select_all( data = revisions.all(
'SELECT DISTINCT r.author AS author, p.name AS page_name ' + :select => "DISTINCT revisions.author AS author, pages.name AS page_name",
'FROM revisions r ' + :order => "pages.name"
'JOIN pages p ON r.page_id = p.id ' + )
"WHERE p.web_id = #{self.id} " +
'ORDER by p.name').inject({}) { |result, row| data.inject({}) do |result, revision|
author, page_name = row['author'], row['page_name'] result[revision.author] ||= []
result[author] = [] unless result.has_key?(author) result[revision.author] << revision.page_name
result[author] << page_name result
result end
}
end end
def remove_pages(pages_to_be_removed) def remove_pages(pages_to_be_removed)