2010-04-18 47 views
0

我正在开发一个具有海量数据条目的应用程序。 就像Campaign一样,它有类似rate_per_sq_feet,start_date,end_date。即它的最大日期约为30天。在Rails中存储前一年的旧数据?

活动结束后,完成活动并开始活动。 现在我很困惑,如何将这些广告系列存储为报告,以避免其被长期访问。我的意思是以这样一种方式进行存储,以便在未来几年发布报告。

它的帐户类似于财政年度,其中前一年的报表会与所有计算一起存储,以便稍后检索时不应执行所有算法和计算。像冻结的数据?

回答

0

您可以将活动报告存储在数据库或文件系统中。该报告可以在第一次存档活动请求时生成。

class Campaign < ActiveRecord::Base 
    # Campaign model has an attribute called report_file 
    def report_file 
    return nil unless expired? 
    attributes['report_file'] ||= generate_report_file 
    end 

    def generate_report_file 
    return nil if attributes['report_file'] 
    # Generate the report using Prawn PDF OR wickedPDF etc. 
    # Update report_file attribute with the report file location 
    # Return the file location 
    end 
end 

class CampaignsController < ApplicationController 
    before_filter :check_expiry, :only => :show 
    def report 
    if @campaign.report_file 
     send_file(@campaign.report_file) 
    else 
     # handle error 
    end 
    end 
    def show 
    end 
    def check_expiry 
    @campaign = Campaign.find(params[:id]) 
    if @campaign.expired? 
     render :report 
    end 
    end 
end 
+0

感谢您的好解释。我会在尝试后回来。 – Autodidact 2010-04-18 20:01:24

相关问题