Permalink
Browse files

Cache the queries that are executed

  • Loading branch information...
mdespuits committed Apr 4, 2012
1 parent 089f34b commit 5c6c8dbc9d3180b76858619c44e9a32bca2ac3bb
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/transplant/planter.rb
@@ -6,10 +6,14 @@ class Planter
def initialize(app_name, connection)
@app_name = app_name
@connection = connection
+ @queries ||= []
+ @results ||= {}
end
def query(sql)
- @connection.execute sql
+ return @results[sql] if @queries.include?(sql)
+ @queries << sql
+ @results[sql] = @connection.execute(sql)
end
def save(klass, other = {})

0 comments on commit 5c6c8db

Please sign in to comment.