Created
August 19, 2011 19:45
-
-
Save michaelfeathers/1157806 to your computer and use it in GitHub Desktop.
Slow Resque
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perform | |
@results ||= {} | |
puts "Looking up query" | |
query = Query.find_by_id(options["query_id"]) | |
engine = Quote::Engine.create(query) | |
puts "Finding quotes" | |
quotes = engine.find_quotes(options["options"]) | |
puts "Found quotes" | |
# NOTE: | |
# This is here so that sorting and filtering can take advantage | |
# of the unsorted/unfiltered data | |
puts "Merging quotes" | |
@results.merge!( | |
:no => quotes, | |
:yes => quotes | |
) | |
puts "Quotes merged" | |
puts "Sorting Quotes" | |
puts "There are #{quotes.size} quotes" | |
sorted_quotes = query.sort_results(quotes) | |
puts "Quotes Sorted" | |
filtered_quotes = @results.merge!( | |
:no => sorted_quotes, | |
:yes => query.filter_results(quotes) | |
)[options["options"][:filter]] | |
p filtered_quotes | |
puts "Running Quotes" | |
filtered_quotes.each_with_index do |quote,current| | |
at(current, quotes.size, "At #{current} of #{quotes.size}") | |
puts "Making json" | |
p quote.as_json | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment