defbill_inventory_valuation_detailsproductsbill_items=PurchaseOrderBillItem.joins(:purchase_order_bill=>:purchase_order).includes(:purchase_order_bill=>:purchase_order).where("purchase_order_bills.status = ?",PurchaseOrderBill::STATUS[:finished]).where("purchase_order_bills.date BETWEEN ? AND ?",@start_date,@end_date).where("purchase_order_bill_items.product_id IN (?)",products.pluck(:id)).group_by(&:product_id)enddefsell_inventory_valuation_detailsproductssell_items=OutStorageOrderItem.joins(:out_storage_order).includes(:out_storage_order).where("out_storage_orders.out_storage_order_type = ?",3).where("out_storage_orders.created_at BETWEEN ? AND ?",@start_date.beginning_of_day,@end_date.end_of_day).where("out_storage_orders.package_id IS NOT NULL OR out_storage_orders.package_group_id IS NOT NULL").where("out_storage_order_items.product_id IN (?)",products.pluck(:id)).group_by(&:product_id)enddefadjust_inventory_valuation_detailsproductsadjust=AdjustInventoryRecord.where("the_date BETWEEN ? AND ?",@start_date,@end_date).where(product_id:products.pluck(:id)).group_by(&:product_id)enddefpackage_inventory_valuation_detailsproductspackage_items=PackageItem.eager_load(:package).where(product_id:products.pluck(:id)).where("packages.state = ?",Package::STATE_VALUES[:processed]).where("packages.dropship = ?",false).where("packages.shipped_at >= ? AND packages.shipped_at <= ?",@start_date,@end_date).group_by(&:product_id)end
(controller.action_methods.to_a-excepts).eachdo|action|need_imports<<Permission.new(subject:subject,action:action,description:"#{action.humanize} of #{subject}")endPermission.importneed_imports
这样已经很快了,还有更快的吗?
2.2 INFILE文件插入数据
From MySQL Doc:
When loading a table from a text file, use LOAD DATA INFILE. This is usually 20 times faster than using INSERT statements