Permalink
Browse files

optimized has_many_proxy a bit

  • Loading branch information...
1 parent 50a7cdd commit 4bfe91f0c6d307b2bcb817aacb5bac0510943545 Dmitrii Samoilov committed Sep 3, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/redis_orm/associations/has_many_proxy.rb
@@ -12,6 +12,10 @@ def initialize(receiver_model_name, reciever_id, foreign_models, options)
@fetched = false
end
+ def receiver_instance
+ @receiver_instance ||= @reciever_model_name.camelize.constantize.find(@reciever_id)
+ end
+
def fetch
@records = @foreign_models.to_s.singularize.camelize.constantize.find($redis.zrevrangebyscore __key__, Time.now.to_f, 0)
@fetched = true
@@ -32,7 +36,7 @@ def to_a
def <<(new_records)
new_records.to_a.each do |record|
$redis.zadd(__key__, Time.now.to_f, record.id)
- receiver_instance = @reciever_model_name.camelize.constantize.find(@reciever_id)
+
receiver_instance.set_expire_on_reference_key(__key__)
record.get_indices.each do |index|

0 comments on commit 4bfe91f

Please sign in to comment.