問題タブ [activerecord-import]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
mysql - 大きなデータセットをRailsアプリケーションにロードする
Railsアプリケーションにモデルとしてロードしたい何百万行ものデータを扱っています。私はデータベースとしてMySQLを使用しており、Rails2.3.14を使用しています。
私の同僚の1人は、Rails ActiveRecordシステムをバイパスして、MySQLに直接レコードを追加することはお勧めできないと言っています。彼は詳細が不足していますが、その要点は、RailsがActiveRecordシステムを使用すると多くの「魔法」を実行し、このシステムの外部でデータを入力するとRailsを混乱させるということです。誰かがこれが正確かどうかについて詳しく説明できますか?
ActiveRecordを介してRailsにデータをロードする必要がある場合は、activerecord-importプラグインがこのタイプのジョブを実行する方法であることを読みました。
大量のデータをRailsにロードするための最良のアプローチに関するフィードバックを歓迎します。
ruby-on-rails - activerecord-import gem NoMethodError: 未定義のメソッド 'import'
私は activerecord-import gem を使用しようとしています。wiki の指示に従ってティーを作成しましたが、NoMethodError: undefined method 'import' for #<Class:0x8b009b0>
. これが私のコードです(基本的にwikiの例と同じです)
メソッドを次のように呼び出します。
Windows、Linux、sqlite データベース、mysql データベースで試しましたが、まだうまくいきません。そして、私は宝石がインストールされていると確信しています:
私はrequireを使用しようとしました(gemがインストールされている場合は必要ありません。これは他の場所では見られなかったので、非常に明白なものを見逃さなければならないのではないかと心配しています
ruby-on-rails - activerecord-importgemからインポートを実行するとPostgresがエラーをスローします
開発中にPostgresに切り替えましたが、次のエラーでテストケースが壊れます。
開発環境と本番環境でも同じエラーが発生しますが、これはショーストッパーではなく、インポートには影響しません。Assets_content_nodesは結合テーブルであり、「id」列を追加したくありません。なぜこれが起こっているのか考えはありますか?
ruby-on-rails - 大量インポートエラーを引き起こす問題のあるデータ行を特定する
activerecord-importを使用して、.csvファイルの大量のデータをRailsアプリに一括挿入しています。残念ながら、モデルでimportを呼び出すと、エラーが発生します。
問題は、インポートしている1000行以上のデータのどこかに奇妙な文字を含む文字列があることですが、どの行が問題であるかがわかりません。
activerecord-importには、問題のある行を特定するために使用できるエラー処理が組み込まれていますか(たとえば、モデルでインポート関数を呼び出すときに設定できるオプション)?私が知る限り、答えはノーです。
または、activerecord-importに渡す配列をチェックして、UTF-8で無効な文字列が含まれている行を特定するコードを記述できますか?
ruby - How do I improve process performance converting a file to array of hashes?
I am using this method to process a single text file that has about 220,000 lines. It takes a few minutes to process one, but I have lots of them. Are there any recommendations to make this process faster?
Update:
Originally, I thought there was massive time savings from using Nex and thetinman's methods so I went on to test them keeping the parsing method consistent.
Using my original r[].strip
parsing method, but with Nex's each_line
block method and thetinman's foreach
methods:
Running again using thetinman's unpack.map
parsing method:
unpack.map(&:strip)
vs r[].strip
: unpack
with map
does not seem to increase speed, but is an interesting method to use in the future.
I found a different issue: With the substantial time savings found, I thought, I went on to run Nex and thetinman's methods manually using pry. This is where I found my computer hanging, just like my original code. So I went on to test again, but with my original code.
My code, Nex, and thetinman's methods seem comparable, with Nex being the fastest using Benchmark. However, Benchmark does not seem to tell the whole story because using pry to test the code manually gets all the methods to take substantially longer, so long that I cancel out before getting the result back.
I have some remaining questions:
- Is there something specific about running something like this in IRB/Pry that would produce these strange results, making the code run massively slower?
- If I run
original_method.count
,nex_method.count
, orthetinmans_method.count
, they all seem to return quickly. - Due to memory issues and scalability, it is recommended by thetinman and nex that the original method should not be used. However, in the future are there ways to test memory usage with something like benchmark?
Update for NEX, using activerecord-import
:
@nex, is this what you mean? This seems to run slow for me still, but I'm not sure what you mean when you say:
import one set of data inside that block.
How do you recommend modifying it?
Results from the activerecord-import
method are, as you can see, substantially slower:
Does this slow import process seem normal?
It just seems super slow to me. I'm trying to figure out how to speed this up, but I am out of ideas.
ruby-on-rails - コールバックを使用して 1 つのクエリで複数のレコードを保存する方法
アクティブなレコードの新しいオブジェクトの配列があり、それらをすべて 1 つのクエリに保存し、before_create コールバックも呼び出したいと考えています。私はactiverecored-import gemを使用し、insertメソッドでも試しましたが、これらの両方のメソッドがコールバックをスキップしました。これを行う最善の方法は何ですか?
ruby-on-rails - Railsのモデルレステーブルに「activerecord-import」gemを利用することは可能ですか?
モデルを持たないテーブルにレコードを一括挿入したい。Rails 3で一括挿入を実装する方法のリンクをたどりました..「インポート」コマンド以外はすべて問題ありませんでした。私はモデルを持っていないので。
そのテーブルに空のモデルを作成できません。わかりました、なぜそのためのテーブルを作成できないのか教えてください。プッシュ通知機能に IOS apns サーバーを使用しています。それを構成すると、モデルなしでデータベースに多くのテーブルが作成されました。これらのテーブルの 1 つで、単一のクエリでレコードを一括挿入したいと考えています。最初はループでやりました。それはパフォーマンスに影響を与えました。だから、私は最適化をしたかったのです。解決策が何であれ、何か提案してください。以下は私の方法です。
下手な英語でごめんなさい。前もって感謝します。
ruby-on-rails - オブジェクトをアレイ レール 4 にプッシュする方法
gem 'activerecord-import'
Railsアプリケーションでの一括インポートに使用しています。次のようなサンプルコードがあります。
このコードでは、数秒で 10000 件の新しいレコードをインポートしています。しかし、次のような記事のコメントを大量に作成している場合:
上記のコードを実行すると、配列にプッシュされることなく、ループ内にコメントが作成されます。作成前にすべてのコメントを配列にプッシュするにはどうすればよいですか。助けてください。