-
Notifications
You must be signed in to change notification settings - Fork 22
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
CCOL-2440: Add consumer configuration to save associated keys prior to saving primary record #217
Conversation
@lionelpereira can you provide some more information in this PR as to what the use case is here and why it isn't covered by existing functionality? |
@dorner Updated the PR description |
lib/deimos/config/configuration.rb
Outdated
@@ -476,6 +477,8 @@ def self.configure_producer_or_consumer(kafka_config) | |||
# @return [Block] | |||
setting :bulk_import_id_generator, nil | |||
|
|||
setting :backfill_associations, false |
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.
YARD comment please.
I'm not sure I like the naming of this... You're actually backfilling the main record with the association IDs. Maybe something as simple as save_associations_first
?
associations = {} | ||
record_list.associations.each do |assoc| | ||
col = @bulk_import_id_column if assoc.klass.column_names.include?(@bulk_import_id_column) | ||
associations[[assoc.name, assoc.klass, col, assoc.foreign_key]] = [] |
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.
Feels like you should be able to just use [assoc, col]
and reference what you need out of the association further down?
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.
Also you don't need to do this up-front - just change line 93 to associations = Hash.new([])
which will put an empty array as the default for any key instead of nil.
# Associate this associated batch record's record with the primary record to | ||
# retrieve foreign_key after associated records have been saved and primary | ||
# keys have been filled | ||
primary_batch_record.record.send(:"#{assoc}=", batch_record.record) |
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.
Pretty sure you can do primary_batch_record.record[assoc] = batch_record.record
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 was getting a NoMethodError
when I tried this
case klass.to_s | ||
when 'Widget', 'Fidget' | ||
%w(id) | ||
when 'WidgetFidgets' |
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.
Why is this the only one that's plural?
record_list.associations.each do |assoc| | ||
col = @bulk_import_id_column if assoc.klass.column_names.include?(@bulk_import_id_column) | ||
associations[[assoc, col]] = [] | ||
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.
You should be able to remove lines 95-98.
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 would still need these lines to determine the bulk_import_column
instead of checking for each batch record
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.
Ah - didn't make the connection between this and line 100. -_- Maybe rename associations
to something else - it's mirroring record.associations
but isn't actually recording the same thing.
In that case there's no need to use Hash.new([])
.
@@ -84,15 +87,60 @@ def import_associations(record_list) | |||
end | |||
end | |||
|
|||
# rubocop:disable Metrics/AbcSize |
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.
Let's not disable this - if it's complaining, the function is too big. Let's break it up.
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 think this works!
Pull Request Template
Description
Normal bulk consumption logic:
Backfill consumption logic (this change)
Notes:
widget_id
,fidget_id
are requiredwidget_id
,fidget_id
) of associated records are filled from DBHow Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: