Skip to content

[SEARCH-792] Raw Imports for Custom Object Records, adding 3rd param to chewy crutch#20

Merged
marynadub merged 8 commits intomasterfrom
maryna/crutch_new_param
May 28, 2025
Merged

[SEARCH-792] Raw Imports for Custom Object Records, adding 3rd param to chewy crutch#20
marynadub merged 8 commits intomasterfrom
maryna/crutch_new_param

Conversation

@marynadub
Copy link
Collaborator

@marynadub marynadub commented May 27, 2025

Added possibility to provide update_fields param to be passed to crutch function.
update_fields is added on Crutches level during initialization in BulkBuilder for further usage in AbstractZpChewyIndex.traced_crutch (added to args for crutch invocation)


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the changelog if the new code introduces user-observable changes. See changelog entry format for details.

@marynadub marynadub requested a review from akshay-apollo May 27, 2025 14:43
execution_block = @index._crutches[:"#{name}"]
@crutches_instances[name] ||= if execution_block.arity == 2
@crutches_instances[name] ||= if execution_block.arity == 3
execution_block.call(@collection, self, options)

Choose a reason for hiding this comment

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

Why are we passing options here? We should be passing @update_fields right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

options is a hash, which contains update_fields key. If we decise in the future to add more params to the crutch, we won't need to change arity, just add another key to options.

@akshay-apollo akshay-apollo requested a review from Copilot May 28, 2025 13:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for passing an update_fields parameter through the BulkBuilder into the Crutches mechanism to allow crutch functions to receive a third argument when needed.

  • BulkBuilder now initializes Crutches with update_fields: @fields.
  • Crutches is updated to accept update_fields in its initializer and dispatch blocks with arity 3.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/chewy/index/import/bulk_builder.rb Pass update_fields: @fields when constructing Crutches
lib/chewy/index/crutch.rb Extend Crutches initializer and [] method to accept and forward update_fields
Comments suppressed due to low confidence (2)

lib/chewy/index/crutch.rb:29

  • Defining update_fields as a method parameter shadows the instance variable set in initialize and requires callers to supply it on every lookup. Consider removing the parameter here and using @update_fields from the initializer to keep the API simpler and consistent.
def [](name, update_fields = [])

lib/chewy/index/crutch.rb:31

  • [nitpick] Memoizing crutch instances by name alone may lead to stale instances if update_fields vary. Consider incorporating update_fields into the cache key or ensuring the instance-level @update_fields is consistently applied.
if execution_block.arity == 3


def crutches_for_index
@crutches_for_index ||= Chewy::Index::Crutch::Crutches.new @index, @to_index
@crutches_for_index ||= Chewy::Index::Crutch::Crutches.new @index, @to_index, update_fields: @fields

Choose a reason for hiding this comment

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

Should we update other places too, which have crutches.new, and if they have fields available, to pass it from there?

@marynadub marynadub merged commit b9f61c9 into master May 28, 2025
1 of 11 checks passed
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.

3 participants