我们有一个自定义顺序导出脚本,运行不足。出口小的时间范围工作正常,但由于假期出口12月份的所有12月份的订单(比平时更多)。)

我添加了一些日志语句,以便在进程中的各个点处给我内存用量,并在较小的时间范围内运行导出。似乎秒杀在渲染报告时发生。

Beginning of controller action Memory: 5.84M <database query happens at this point> after getReport() Memory: 19.48M <now Magento prepares our HTML output> End of controller action Memory: 44.14M *导出大型数据集时,“控制器操作结束”永远不会达到。

我们真的只需要使用CSV导出功能,但我们甚至无法到达那样,因为您必须在单击“导出”之前“刷新”网格。

简短于重新写作这是一个独立的报告(在Magento之外)我不确定该怎么办。任何人?

有帮助吗?

解决方案

所以我最终做了什么是黑客攻击报告,以便您可以首先在不加载网格的情况下运行CSV导出,通过指定URL末尾的AS_CSV。

首先,我将此小片段添加到索引中,以有效地将请求重新路由到ExportCsvaction(如果在URL中设置)。

public function indexAction() {
    if(isset($_GET['as_csv'])) {
        $this->exportCsvAction();
        return;
    }

    $this->_initAction()
            ->renderLayout();
}
. 现在我们可以采取日期选择器生成的任何URL,将其添加到它,并在该日期范围内获得CSV导出。 然后我将此JavaScript代码添加到报表索引页面(通过XML布局):
// This is how the "Refresh" button generates the URL for the date range.
varienGrid.prototype.getFilter = function(){
    var filters = $$('#'+this.containerId+' .filter input', '#'+this.containerId+' .filter select');
    var elements = [];
    for(var i in filters){
        if(filters[i].value && filters[i].value.length) elements.push(filters[i]);
    }
    if (!this.doFilterCallback || (this.doFilterCallback && this.doFilterCallback())) {
        return this.addVarToUrl(this.filterVar, encode_base64(Form.serializeElements(elements)));
    }
}
// This is the function that the "Export" button calls. Overwrite it and add the ?as_csv queryString
varienGrid.prototype.doExport = function() {
    window.location = this.getFilter() + '?as_csv';
}
.

虽然这不是最优雅的解决方案,但对于具有这种独特问题的其他人来说是一个可重复使用的解决方案。

许可以下: CC-BY-SA归因
scroll top