Home Should I use hashes or ActiveRecord::Relations?
Reply: 0

Should I use hashes or ActiveRecord::Relations?

user8217653 Published in 2018-01-02 18:58:27Z

I'm really lacking some knowledge regarding efficiency/performance when working with massive amount of data.

I need to do some calculations on different models and then updating them. I was thinking:

Step I. Get the data from each table in hashes (hash_table_1, hash_table_2 etc) "plucking" the active record relations and then map it in a hash

Step II. Do calculations and change the values in the hashes (iterate over hashes, searching ids in hashes); doing them directly in sql is a big NO-NO, since I have instructions not do it, I'm contemplating If I should do them on active records and then update, but I will have to update a lot of them.

Step III. Updating data with Table_1.update(hash_table_1), Table_2.update(hash_table_2) etc. OR use raw SQL to update

Should I be using ActiveRecord::Relations instead of hashes? Are they more memory efficient?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330905 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO