| only reading the relevant cached data now - reportable - Fork of reportable req… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 0080b2cf29f53a7f20991bab2056766fd6d5bf27 | |
| parent 32bffbc899f2b374c80af845ac46dd9b94c6efd8 | |
| Author: Marco Otte-Witte <[email protected]> | |
| Date: Tue, 13 Jan 2009 19:34:23 +0800 | |
| only reading the relevant cached data now | |
| Signed-off-by: Marco Otte-Witte <[email protected]> | |
| Diffstat: | |
| M lib/kvlr/reports_as_sparkline/repo… | 14 ++++++++------ | |
| M spec/other/report_cache_spec.rb | 14 ++++++++------ | |
| 2 files changed, 16 insertions(+), 12 deletions(-) | |
| --- | |
| diff --git a/lib/kvlr/reports_as_sparkline/report_cache.rb b/lib/kvlr/reports_a… | |
| @@ -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 aggre… | |
| + 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' | |
| ) | |
| 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… | |
| + @report.klass.to_s, | |
| + @report.name.to_s, | |
| + @report.grouping.identifier.to_s, | |
| + @report.aggregation.to_s, | |
| + Kvlr::ReportsAsSparkline::ReportingPeriod.first(@report.grouping, 10… | |
| + ], | |
| :limit => 10, | |
| :order => 'reporting_period ASC' | |
| ) |