added enable_grouping option to disable grouping features, enabled by default

This commit is contained in:
2011-03-04 13:02:20 +00:00
parent 7b1feda061
commit fe221c3f31
3 changed files with 18 additions and 4 deletions

View File

@@ -31,7 +31,10 @@ module Redistat
end
def default_options
{ :depth => :hour, :store_event => false, :connection_ref => nil }
{ :depth => :hour,
:store_event => false,
:connection_ref => nil,
:enable_grouping => true }
end
def new?
@@ -72,7 +75,7 @@ module Redistat
def save
return false if !self.new?
Summary.update_all(@key, @stats, depth_limit, @connection_ref)
Summary.update_all(@key, @stats, depth_limit, @connection_ref, @options[:enable_grouping])
if @options[:store_event]
@id = self.next_id
db.hmset("#{self.scope}#{KEY_EVENT}#{@id}",

View File

@@ -2,9 +2,10 @@ module Redistat
class Summary
include Database
def self.update_all(key, stats = {}, depth_limit = nil, connection_ref = nil)
def self.update_all(key, stats = {}, depth_limit = nil, connection_ref = nil, enable_grouping = nil)
stats ||= {}
stats = inject_group_summaries(stats)
enable_grouping = true if enable_grouping.nil?
stats = inject_group_summaries(stats) if enable_grouping
depth_limit ||= key.depth
return nil if stats.size == 0
Date::DEPTHS.each do |depth|

View File

@@ -67,4 +67,14 @@ describe Redistat::Summary do
summary["visitors/us"].should == "4"
end
it "should not store key group summaries when option is disabled" do
stats = {"views" => 3, "visitors/eu" => 2, "visitors/us" => 4}
Redistat::Summary.update_all(@key, stats, :hour, nil, false)
summary = db.hgetall(@key.to_s(:hour))
summary.should have(3).items
summary["views"].should == "3"
summary["visitors/eu"].should == "2"
summary["visitors/us"].should == "4"
end
end