lib/seymour/feed.rb in seymour-0.0.5 vs lib/seymour/feed.rb in seymour-0.0.6

- old
+ new

@@ -25,31 +25,41 @@ def activity_ids redis.lrange(key, 0, max_size).map{|id| id.to_i } end - def push(activity, cmd = :lpush) - perform_push(activity.id, cmd) if should_push?(activity) + def push(activity) + perform_push(activity.id) if should_push?(activity) end + def bulk_push(activities) + activities.each do |activity| + push(activity) + end + end + def remove(activity) remove_id activity.id end def remove_id(activity_id) redis.lrem(key, 0, activity_id) end - def insert_and_order(activities) - ids = (activity_ids.map(&:to_i) + activities.map(&:id)).sort.uniq + def sort!(options = {}) + sort({ :order => "DESC", :store => key }.merge(options)) # replaces itself with sorted list + end - remove_all + def sort(options = {}) + redis.sort(key, options) + end - ids.each do |id| - perform_push(id) - end + def sorted_push(activities) + bulk_push(activities) + sort! end + alias_method :insert_and_order, :sorted_push protected def redis @redis ||= Seymour.redis @@ -78,14 +88,14 @@ def max_size 100 end def should_push?(activity) - true + !activity_ids.include?(activity.id) end - def perform_push(activity_id, cmd = :lpush) - redis.send(cmd, key, activity_id) + def perform_push(id) + redis.lpush(key, id) redis.ltrim(key, 0, max_size) end end end