From fe221c3f31e43e90d6978f3962749ab91bec492c Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Fri, 4 Mar 2011 13:02:20 +0000 Subject: [PATCH] added enable_grouping option to disable grouping features, enabled by default --- lib/redistat/event.rb | 7 +++++-- lib/redistat/summary.rb | 5 +++-- spec/summary_spec.rb | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/redistat/event.rb b/lib/redistat/event.rb index 54cb936..f22b162 100644 --- a/lib/redistat/event.rb +++ b/lib/redistat/event.rb @@ -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}", diff --git a/lib/redistat/summary.rb b/lib/redistat/summary.rb index e955812..f1b50ce 100644 --- a/lib/redistat/summary.rb +++ b/lib/redistat/summary.rb @@ -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| diff --git a/spec/summary_spec.rb b/spec/summary_spec.rb index 3c05635..fb1db67 100644 --- a/spec/summary_spec.rb +++ b/spec/summary_spec.rb @@ -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