小编gem*_*art的帖子

Node-Inspector无法启动

首先,我在安装node-inspector时遇到了问题,我不得不恢复安装版本@0.7.5..这在我的机器上全局安装,但是现在当我尝试运行时,node-inspector我得到下面的错误.我发现奇怪的是我无法找到关于这两个错误的很多内容.

module.js:487
    throw err;
    ^
Error: Cannot find module '_debugger'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/node-inspector/lib/debugger.js:2:16)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
Run Code Online (Sandbox Code Playgroud)

debugging node.js node-inspector

14
推荐指数
2
解决办法
7478
查看次数

CSV 解析占用太多内存

我正在尝试读取 5MM 行文件,但现在它超出了我在 heroku 上分配的内存使用量。我的方法有点快~200次插入/秒..我相信它在导入时崩溃了..所以我的计划是批量导入1,000或10,000个。我的问题是我如何知道我在文件的末尾,ruby 有一个.eof方法,但它是一个File方法,我不知道如何在我的循环中调用它

    def self.import_parts_db(file)
        time = Benchmark.measure do
            Part.transaction do 
                parts_db = []
                CSV.parse(File.read(file), headers: true) do |row|
                    row_hash = row.to_hash
                    part = Part.new(
                        part_num: row_hash["part_num"], 
                        description: row_hash["description"], 
                        manufacturer: row_hash["manufacturer"],
                        model: row_hash["model"],
                        cage_code: row_hash["cage_code"],
                        nsn: row_hash["nsn"]
                        )
                    parts_db << part
                end
                Part.import parts_db
            end
        end
        puts time
    end
Run Code Online (Sandbox Code Playgroud)

ruby csv activerecord ruby-on-rails activerecord-import

4
推荐指数
1
解决办法
3789
查看次数