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

fix: count number of elements in change requests #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions lib/roadworker/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def slice_operations(ops)
total_ops = 0
ops.slice_before do |op|
total_value_size += op.value_size
total_ops += 1
if total_value_size > 32000 || total_ops > 1000
total_ops += op.resource_record_set_size
if total_value_size >= 32000 || total_ops >= 1000
total_value_size = op.value_size
total_ops = 1
total_ops = op.resource_record_set_size
true
else
false
Expand Down Expand Up @@ -163,6 +163,20 @@ def value_size
end.sum || 0
end

# Count total size of ResourceRecord element in changes
# See also: Batch#slice_operations
# @return [Integer]
def resource_record_set_size
changes.map do |change|
upsert_multiplier = change[:action] == 'UPSERT' ? 2 : 1
rrset = change[:resource_record_set]
next 0 unless rrset
rrs = rrset[:resource_records]
next 0 unless rrs
rrs.length * upsert_multiplier
end.sum || 0
end

# @return [Array<Hash>]
def changes
raise NotImplementedError
Expand Down Expand Up @@ -311,11 +325,7 @@ def desired_rrset
def changes
[
{
action: 'DELETE',
resource_record_set: present_rrset.to_h,
},
{
action: 'CREATE',
action: 'UPSERT',
resource_record_set: desired_rrset.to_h,
},
]
Expand Down