Checking arrays if exist efficiently

Rails 4.0.0

I am developing an app that checkes information updates automatically.
When the checking algorithms get to work, they receive an array of
contents such as

info_obtained: [‘Tom’, ‘Steven’, ‘Bill’, …]

then, the app needs to check if each element of the array is already
persisted in the database.

Of course, I can loop through all elements like

Info.all.each do | i |
if i == … then
Info.create(… => i)
end
end

But it seems inefficient.

Is there better ways or gems that do the job I am looking for?

soichi

Please, You not fetch all rows from database table. For better way is,
you
can fetch data with filter using ‘where’ cluase and Proceed on data.

Soichi I. wrote in post #1112146:

Rails 4.0.0
Of course, I can loop through all elements like

Info.all.each do | i |
if i == … then
Info.create(… => i)
end
end

But it seems inefficient.

Is there better ways or gems that do the job I am looking for?

soichi

Not sure I understand fully your problem.

Maybe use find_in_batches ?
http://api.rubyonrails.org/classes/ActiveRecord/Batches.html

or find_and_create_by_column_name ?

Sorry about my poor coding and language skills. I appreciate your
comments.

Maybe use find_in_batches ?

or find_and_create_by_column_name ?

will probably help. I’ll take a look.

thanks

Pry F. [email protected] wrote:

But it seems inefficient.
or find_and_create_by_column_name ?
ActiveRecord::Base

It’s also not clear to me what you’re doing with the items. From your
snippet of pseudocode, you want to create a new item with the
matching item when you find a match??