lib/flapjack/data/entity.rb in flapjack-0.7.35 vs lib/flapjack/data/entity.rb in flapjack-0.8.0
- old
+ new
@@ -14,13 +14,15 @@
TAG_PREFIX = 'entity_tag'
def self.all(options = {})
raise "Redis connection not set" unless redis = options[:redis]
- redis.keys("entity_id:*").collect {|k|
+ keys = redis.keys("entity_id:*")
+ ids = redis.mget(keys)
+ keys.collect {|k|
k =~ /^entity_id:(.+)$/; entity_name = $1
- self.new(:name => entity_name, :id => redis.get("entity_id:#{entity_name}"), :redis => redis)
+ self.new(:name => entity_name, :id => ids.shift, :redis => redis)
}.sort_by(&:name)
end
# NB: should probably be called in the context of a Redis multi block; not doing so
# here as calling classes may well be adding/updating multiple records in the one
@@ -169,9 +171,16 @@
enum.each do |t|
tag = Flapjack::Data::Tag.find("#{TAG_PREFIX}:#{t}", :redis => @redis)
tag.delete(@id)
tags.delete(t)
end
+ end
+
+ def as_json(*args)
+ {
+ "id" => self.id,
+ "name" => self.name,
+ }
end
private
# NB: initializer should not be used directly -- instead one of the finder methods