-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ActiveModel::Datastore.save_all feature #27
base: main
Are you sure you want to change the base?
Conversation
oh.. I'll fix code style reported by RuboCop. |
@bmclean please review it. |
Hi @shao1555. I like the concept. Hopefully I will have time to review it in more detail tomorrow. |
@@ -161,6 +161,18 @@ class User | |||
end | |||
``` | |||
|
|||
To improve performance, you can save many entities at once. (Batch operation) |
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.
At this position in the README we have not yet mentioned the concept of parent/ancestor. Let's move this new section down after Datastore Consistency.
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 is some really nice work @shao1555!
```ruby | ||
group = Group.find(params[:group_id]) | ||
users = %w{ alice bob charlie }.map{ |name| User.new(name: name) } | ||
if ActiveModel::Datastore.save_all(users, parent: group) |
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.
I believe passing in the group model object to parent
will fail. It needs to be a Google::Cloud::Datastore::Key.
end | ||
end | ||
|
||
test 'batch save' do |
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.
We should also add a test where the parent
is explicitly passed in.
sliced_entries | ||
end.flatten | ||
end | ||
end |
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.
What would we expect this method to return? It is currently returning an array of model objects. Should it return an array of Google::Cloud::Datastore::Entity instead?
Also, is the results.present?
line needed?
@shao1555 This is ready for your feedback. |
Hi @bmclean any particular reason why was this not merged yet? I am looking for the same functionality :-) I'll do a fork and try to clean it up. |
Hi @NielsKSchjoedt. This was a proof of concept that was never completed. We left it here in case somebody wanted to pick it up again. |
Also, one thing we have learned since this feature was started is that a batch size of 500 won't always work. See While 500 is the max number of entities that can be passed to Datastore sometimes we hit the size limit first. We should set the default to 250 and allow a batch size to be passed in (up to 500). |
@bmclean great. If I am to finish it I will add both a |
@NielsKSchjoedt Sure, |
Motivation
I want to use bulk insert feature to improve performance.
Resolution
implement
ActiveModel::Datastore.save_all(entries)
in case of 500 records insertion, 200x faster than before.
Remark
I'm not good for English. please feel free to update comment and document :)