Skip to content
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 batch operations #27

Merged
merged 4 commits into from
Feb 7, 2018
Merged

Add batch operations #27

merged 4 commits into from
Feb 7, 2018

Conversation

AMHOL
Copy link
Contributor

@AMHOL AMHOL commented Feb 6, 2018

Example:

class User < ActiveRecord::Base
  include Nazrin::Searchable

  searchable_configure do |config|
    # My config
  end

  searchable do
    fields [:name, :email]
  end
end
# Create some users
user_1 = User.create(name: 'Jane', email: 'no-reply@jane-fake-email.com')
user_2 = User.create(name: 'Joe', email: 'no-reply@joe-fake-email.com')
user_3 = User.create(name: 'John', email: 'no-reply@john-fake-email.com')
# Delete a user
user_3.destroy

User.nazrin_batch_operation(
  add: [user_1, user_2],
  delete: [user_3]
)

@tsuwatch tsuwatch self-requested a review February 6, 2018 06:43
hash[:add] = objects.map do |obj|
[obj.send(:id), nazrin_eval_field_data(obj)]
end
else
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like you to specify delete for typo

@@ -81,6 +81,22 @@ def nazrin_add_document(obj)
obj.send(:id), nazrin_eval_field_data(obj))
end

def nazrin_batch_operation(type_objects_mapping)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AMHOL
Copy link
Contributor Author

AMHOL commented Feb 7, 2018

Thanks for review @tsuwatch, I also added create as an alias of add and destroy as an alias of delete, and made it raise an error if the operations are not one of the above.

@AMHOL
Copy link
Contributor Author

AMHOL commented Feb 7, 2018

Let me know if you want me to squash commits

@tsuwatch
Copy link
Owner

tsuwatch commented Feb 7, 2018

Why need create and destroy?

@AMHOL
Copy link
Contributor Author

AMHOL commented Feb 7, 2018

I just thought I may as well add them as aliases as they're familiar methods for people using Rails, I can remove if you like?

)
end
when :delete, :destroy
tuple.map do |id|
Copy link
Contributor Author

@AMHOL AMHOL Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna change this to each rather than map as map implies that the return value matters.

@tsuwatch
Copy link
Owner

tsuwatch commented Feb 7, 2018

Hmm, I think It is not necessary to support the aliases.

@AMHOL
Copy link
Contributor Author

AMHOL commented Feb 7, 2018

@tsuwatch removed

@tsuwatch tsuwatch merged commit e38d7b6 into tsuwatch:master Feb 7, 2018
@tsuwatch
Copy link
Owner

tsuwatch commented Feb 7, 2018

Nice work, thank you!!!

@AMHOL
Copy link
Contributor Author

AMHOL commented Feb 7, 2018

Thanks @tsuwatch 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants