-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
Needed for metrics and streaming_upsert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moar perf!
LGTM, except for the build being borked which I am sure is a minor derp.
lib/active_stash/search.rb
Outdated
records = find_each.lazy.map do |r| | ||
if r.stash_id.nil? | ||
raise "Cannot index record ID=#{r.id} without a stash ID" | ||
end | ||
{ id: r.stash_id, record: r.attributes } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code will only work for collections that have been indexex previously. The save!
call in the old code would use ActiveRecord callbacks to ensure that a stash_id
was set. This approach means a stash_id
will never be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, actually (heh), this approach means that the reindex will fail, because it'll raise
when it it hits the record that doesn't have a stash_id
. Calling #save!
to set a stash ID won't work, because that'll also trigger an upsert
, and that's not great because (a) an upsert
-per-row is exactly what we're trying to avoid, and (b) we're in the middle of a putStream
RPC just at the moment so trying to jam a put
down the middle of that will end poorly.
Use streaming_upsert for reindexing, which makes things much quicker.