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 binding to determine which method to use in relationship mixin #20274

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Jun 12, 2020

we're trying to remove genealogy. since the relationship adding logic lives in the rel mixin, we need a way of differentiating that logic from actual ancestry logic so classes can use both.

based on the value of skip_relationships we need to either set an ancestry parent or a relationship parent

both parent= live on the ancestors that are proxies to each of the modules so you can call methods on any such ancestor with ruby magic wherein you can unbind a method and bind it to some other object.

@miq-bot assign @kbrock

@miq-bot miq-bot added the wip label Jun 12, 2020
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch from 20d1e2e to d3298cd Compare June 12, 2020 13:37
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch from d3298cd to 0df8369 Compare June 12, 2020 17:36
@d-m-u d-m-u requested a review from gtanzillo as a code owner June 12, 2020 17:36
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch 6 times, most recently from 3744bce to ccc2cb4 Compare June 13, 2020 05:55
Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

this looks great.

  1. sorry, but I like the guard clause, it has less changes
  2. yea, since the arguments are different for ancestry and this, we probably need to pass args
  3. pass in ancestry parameters and not tge params that we require. I do wonder if we can drop the *_args parameters.
  4. I'm a little worried about the differences in parent= - moving to update(:parent => ) or setting the parent when the vm is created may be our best bet
  5. think batch refresh (openshift and at least 1 other) may feel this change

app/models/mixins/relationship_mixin.rb Outdated Show resolved Hide resolved
app/models/mixins/relationship_mixin.rb Outdated Show resolved Hide resolved
app/models/mixins/relationship_mixin.rb Outdated Show resolved Hide resolved
app/models/mixins/relationship_mixin.rb Outdated Show resolved Hide resolved
app/models/mixins/relationship_mixin.rb Outdated Show resolved Hide resolved
app/models/mixins/relationship_mixin.rb Outdated Show resolved Hide resolved
lib/patches/ancestry_patch.rb Outdated Show resolved Hide resolved
app/models/vm_or_template.rb Outdated Show resolved Hide resolved
spec/models/mixins/relationship_mixin_spec.rb Outdated Show resolved Hide resolved
app/models/mixins/relationship_mixin.rb Outdated Show resolved Hide resolved
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch from ccc2cb4 to 53f689a Compare June 13, 2020 18:04
@d-m-u d-m-u closed this Jun 13, 2020
@d-m-u d-m-u reopened this Jun 13, 2020
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch 3 times, most recently from 596af70 to 55e779a Compare June 13, 2020 23:14
d-m-u added a commit to d-m-u/manageiq-cross_repo-tests that referenced this pull request Jun 14, 2020
d-m-u added a commit to d-m-u/manageiq-cross_repo-tests that referenced this pull request Jun 14, 2020
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch from 55e779a to 2f6afdb Compare June 14, 2020 03:05
@d-m-u
Copy link
Contributor Author

d-m-u commented Jun 14, 2020

@kbrock you were right about the args getting stomped, it's somewhere around https://github.com/matthewrudy/memoist/blob/v0.15.0/lib/memoist.rb#L213 which is the reason why i have that gook

@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch 3 times, most recently from c55a649 to d5daeea Compare June 14, 2020 17:11
Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

thanks for these changes - this looks great.

Anything outstanding or can we un-WIP it?

parent.with_relationship_type(relationship_type) { parent.add_child(self) }
end

def add_children(*child_objs)
return child_objs.each { |child| child.with_relationship_type(relationship_type) { child.update!(:parent => self) } } if use_ancestry?

Copy link
Member

Choose a reason for hiding this comment

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

well regardless, either the child will have the wrong parent or the parent will have the wrong children. This is the nature of active record in general. I'm ok with this line.

app/models/mixins/relationship_mixin.rb Show resolved Hide resolved
ancestor_ids.include?([obj.class.base_class.name, obj.id])
end

def is_ancestor_of?(obj)
return obj.with_relationship_type(relationship_type) { obj.descendant_of?(self) } if use_ancestry?
Copy link
Member

Choose a reason for hiding this comment

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

looking up descendant ids is a database call but looking up ancestors is not.

so calling is_descendant_of requires fewer queries.

app/models/mixins/relationship_mixin.rb Show resolved Hide resolved
@d-m-u d-m-u changed the title [wip] add binding to determine which method to use in relationship mixin add binding to determine which method to use in relationship mixin Oct 3, 2020
@miq-bot miq-bot removed the wip label Oct 3, 2020
@kbrock kbrock requested a review from Fryguy October 4, 2020 02:00
@d-m-u d-m-u changed the title add binding to determine which method to use in relationship mixin [WIP] add binding to determine which method to use in relationship mixin Oct 24, 2020
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 24, 2020

marking as work in progress because i'm concerned about the behavior of the class variables:

2.5.5 :001 > Dialog.hidden_attribute_names
 => []
2.5.5 :002 > Vm.hidden_attribute_names
 => []
2.5.5 :003 > ExtManagementSystem.hidden_attribute_names
 => ["aggregate_memory"]
2.5.5 :004 > Vm.hidden_attribute_names
 => ["aggregate_memory"]
2.5.5 :005 > Dialog.hidden_attribute_names
 => ["aggregate_memory"]

see #20664 (comment) for the details

@miq-bot miq-bot added the wip label Oct 24, 2020
@kbrock kbrock self-requested a review October 26, 2020 01:59
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch from 2be70a8 to de934a3 Compare November 1, 2020 01:10
@d-m-u
Copy link
Contributor Author

d-m-u commented Nov 1, 2020

un-work in progressing because the cattr_accessor concern was resolved, see https://github.com/ManageIQ/manageiq/pull/20664/files#r513793189, thanks Jason

@d-m-u d-m-u changed the title [WIP] add binding to determine which method to use in relationship mixin add binding to determine which method to use in relationship mixin Nov 1, 2020
@miq-bot miq-bot removed the wip label Nov 1, 2020
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch from de934a3 to d56ac01 Compare November 1, 2020 01:38
@d-m-u
Copy link
Contributor Author

d-m-u commented Nov 1, 2020

@kbrock could I please get one more review here? 🤞

@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch from d56ac01 to d92e48c Compare November 1, 2020 01:56
Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

I would like to move ahead with this one. we just branched off K and something risky like this needs to be done at the beginning of a release cycle - if we are lucky, then we will be able to remove the need for this by changing all the classes

app/models/mixins/relationship_mixin.rb Outdated Show resolved Hide resolved
@@ -26,6 +27,7 @@ module RelationshipMixin
extend Memoist

cattr_accessor :default_relationship_type
class_attribute :skip_relationships, :default => []
Copy link
Member

Choose a reason for hiding this comment

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

this looks great - although, not sure if we want this to carry across all the classes. Will we tell all classes to skip ancestry that are in the chain? If yes, then this is great.

based on the value of default_relationship_type we need to either
set an ancestry parent or a relationship parent as vms use both

both parent= live on the ancestors that are proxies to each
of the modules so you can call methods on any such ancestor
with some black magic wherein you can unbind a method and
bind it to some other object
@d-m-u d-m-u force-pushed the use_rel_type_to_differentiate_between_module_methods_in_mixin branch from d92e48c to 6fefedb Compare November 2, 2020 02:07
@miq-bot
Copy link
Member

miq-bot commented Nov 2, 2020

Checked commit d-m-u@6fefedb with ruby 2.6.3, rubocop 0.82.0, haml-lint 0.35.0, and yamllint
2 files checked, 36 offenses detected

spec/models/mixins/relationship_mixin_spec.rb

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

Successfully merging this pull request may close these issues.

5 participants