only reading the relevant cached data now - reportable - Fork of reportable required by WarVox, from hdm/reportable.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 0080b2cf29f53a7f20991bab2056766fd6d5bf27
 (DIR) parent 32bffbc899f2b374c80af845ac46dd9b94c6efd8
 (HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com>
       Date:   Tue, 13 Jan 2009 19:34:23 +0800
       
       only reading the relevant cached data now
       
       Signed-off-by: Marco Otte-Witte <marco.otte-witte@simplabs.com>
       Diffstat:
         M lib/kvlr/reports_as_sparkline/repo… |      14 ++++++++------
         M spec/other/report_cache_spec.rb     |      14 ++++++++------
       
       2 files changed, 16 insertions(+), 12 deletions(-)
       ---
 (DIR) diff --git a/lib/kvlr/reports_as_sparkline/report_cache.rb b/lib/kvlr/reports_as_sparkline/report_cache.rb
       @@ -12,12 +12,14 @@ module Kvlr #:nodoc:
                  unless no_cache
                    cached_data = self.find(
                      :all,
       -              :conditions => {
       -                :model_name  => report.klass.to_s,
       -                :report_name => report.name.to_s,
       -                :grouping    => report.grouping.identifier.to_s,
       -                :aggregation => report.aggregation.to_s
       -              },
       +              :conditions => [
       +                'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND reporting_period >= ?',
       +                report.klass.to_s,
       +                report.name.to_s,
       +                report.grouping.identifier.to_s,
       +                report.aggregation.to_s,
       +                last_reporting_period_to_read.date_time
       +              ],
                      :limit => limit,
                      :order => 'reporting_period ASC'
                    )
 (DIR) diff --git a/spec/other/report_cache_spec.rb b/spec/other/report_cache_spec.rb
       @@ -34,12 +34,14 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
            it 'should read existing data for the report from cache' do
              Kvlr::ReportsAsSparkline::ReportCache.should_receive(:find).once.with(
                :all,
       -        :conditions => {
       -          :model_name => @report.klass.to_s,
       -          :report_name => @report.name.to_s,
       -          :grouping => @report.grouping.identifier.to_s,
       -          :aggregation => @report.aggregation.to_s
       -        },
       +        :conditions => [
       +          'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND reporting_period >= ?',
       +          @report.klass.to_s,
       +          @report.name.to_s,
       +          @report.grouping.identifier.to_s,
       +          @report.aggregation.to_s,
       +          Kvlr::ReportsAsSparkline::ReportingPeriod.first(@report.grouping, 10).date_time
       +        ],
                :limit => 10,
                :order => 'reporting_period ASC'
              )