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

Ensure journal is empty #463

Merged
merged 4 commits into from
Dec 19, 2016

Conversation

sergey-kintsel
Copy link
Contributor

Refactor Chewy::Journal
Add multiple retries to apply the journal

@sergey-kintsel sergey-kintsel force-pushed the ensure_journal_is_empty branch 4 times, most recently from 284a784 to aafb78f Compare December 14, 2016 13:53
@DNNX
Copy link
Contributor

DNNX commented Dec 14, 2016

The code looks ok. I sent you a few small remarks in DM. Let's :shipit: after green build.

@sergey-kintsel sergey-kintsel force-pushed the ensure_journal_is_empty branch 3 times, most recently from 08f78fa to 416c816 Compare December 15, 2016 07:34
Copy link

@pr0d1r2 pr0d1r2 left a comment

Choose a reason for hiding this comment

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

Couple possible improvements. Nice testing 😄

else
compose_children(result, *objects)
end if children.present? && !multi_field?
if children.present? && !multi_field?
Copy link

Choose a reason for hiding this comment

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

Please consider splitting whole compose method as my eyes are bleeding:

def compose(object, *parent_objects)
  { name => compose_result(object, parent_objects) }
end

def compose_result(object, *parent_objects)
  objects = ([object] + parent_objects.flatten).uniq
  result = base_result(object, objects)
  return compose_result_with_children(result, objects) if children.present? && !multi_field?
  result
end

def base_result(object, objects)
  if value && value.is_a?(Proc)
    result_from_proc(object, objects)
  elsif object.is_a?(Hash)
    result_from_hash(object)
  else
    object.send(name)
  end
end

def result_from_proc(object, objects)
  if value.arity.zero?
    object.instance_exec(&value)
  elsif value.arity < 0
    value.call(*object)
  else
    value.call(*objects.first(value.arity))
  end
end

def result_from_hash(object)
  if object.key?(name)
    object[name]
  else
    object[name.to_s]
  end
end

def compose_result_with_children(result, objects)
  if result.respond_to?(:to_ary)
    result.to_ary.map { |item| compose_children(item, *objects) }
  else
    compose_children(result, *objects)
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is not connected to my changes) this was changed to make Rubocop happy

Copy link

Choose a reason for hiding this comment

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

Can you please prepare follow-up PR after merging this one?

return if respond_to?(type_class.type_name)
class_eval <<-METHOD, __FILE__, __LINE__ + 1
def self.#{type_class.type_name}
ActiveSupport::Deprecation.warn("`#{self}.#{type_class.type_name}` accessor is deprecated and will be removed soon. Use `#{type_class}` directly instead.")
Copy link

Choose a reason for hiding this comment

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

Please break this long line by using heredoc:

ActiveSupport::Deprecation.warn(<<WARNING.sqish)
  `#{self}.#{type_class.type_name}` accessor is deprecated and will be removed soon.
  Use `#{type_class}` directly instead.
WARNING

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is not connected to my changes) this was changed to make Rubocop happy

Copy link

Choose a reason for hiding this comment

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

Can you please prepare follow-up PR after merging this one?

def until(time)
query = Query.new(time, :lte, nil, false).to_h
search_query = query.merge(fields: ['_id'], size: DELETE_BATCH_SIZE)
index_name = Journal.index_name
Copy link

Choose a reason for hiding this comment

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

We can use delegation:

included do
  delegate :index_name, to: Journal
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, I think that explicit calls are easier) longer, but easier)

Copy link

Choose a reason for hiding this comment

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

OK

end
end

Chewy.massacre
Copy link

Choose a reason for hiding this comment

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

😅

Copy link
Contributor

@DNNX DNNX left a comment

Choose a reason for hiding this comment

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

🚢 🇮🇹

@pyromaniac pyromaniac merged commit 2fcbbb8 into toptal:master Dec 19, 2016
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.

4 participants