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

Ancestry Patch updates/fixes #17511

Merged
merged 2 commits into from
Jun 5, 2018

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented Jun 2, 2018

Fixes the two issues reported in the original PR for the ancestry patches and the memoization of certain methods around it:

Both issues should be addressed by this PR.

Links

Steps for Testing/QA

Run the specs for both manageiq-ui-classic and manageiq-automation_engine with this branch checked out and make sure there are not any spec failures.

@NickLaMuro NickLaMuro mentioned this pull request Jun 2, 2018
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.

Lookin good

@@ -184,7 +184,7 @@ def project?
end

def visible_domains
MiqAeDomain.where(:tenant_id => ancestor_ids.append(id)).joins(:tenant).order('tenants.ancestry DESC NULLS LAST, priority DESC')
MiqAeDomain.where(:tenant_id => ancestor_ids + [id]).joins(:tenant).order('tenants.ancestry DESC NULLS LAST, priority DESC')
Copy link
Member

Choose a reason for hiding this comment

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

Think path_ids is what we want.

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't know it was a thing. Will change.


def parent=(parent)
super
clear_memoized_instance_variables
Copy link
Member

Choose a reason for hiding this comment

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

would feel a little more comfortable returning the original value since people often type x = y = z

  def parent=(parent)
    super.tap { clear_memoized_instance_variables }
  end

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh, I guess ruby had my back on this one...

class Foo
  attr_reader :bar

  def bar= bar_val
    @bar = bar_val
    puts "IT WORKED!"
  end
end

puts (Foo.new.bar = "bar")
puts baz = Foo.new.bar = "baz"
puts "baz = #{baz}"

#=> IT WORKED!   <<<<< output from first bar=
#=> bar          <<<<< output from first inline puts
#=> IT WORKED!   <<<<< output from second bar=
#=> baz          <<<<< output from second inline puts
#=> baz = baz    <<<<< output from third inline puts

Apparently ='s methods don't behave the same as normal methods and always return the input? TMYK 🌈✨🌠

Copy link
Member Author

Choose a reason for hiding this comment

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

Anyway, adding a test because this could end up going bad if this is ever NOT the case.

The Tenant#visible_domains method was doing the following:

    ancestor_ids.append(id)

As part of it's query, which would update the memoized value to be
incorrect and include itself.  Switching it to `path_ids`, which
effectively does:

    ancestor_ids + [id]

Makes sure that a new array is created instead of appending to the
existing one.
Clear out the memoization in the lib/patches/ancestry_patch.rb when the
parent= or parent_id= methods are called.
@NickLaMuro
Copy link
Member Author

@kbrock Should have addressed your comments. Please re-review.

@miq-bot
Copy link
Member

miq-bot commented Jun 4, 2018

Checked commits NickLaMuro/manageiq@f75a572~...3742661 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 1 offense detected

spec/models/tenant_spec.rb

@kbrock kbrock merged commit c6a6bed into ManageIQ:master Jun 5, 2018
@kbrock kbrock added this to the Sprint 88 Ending Jun 18, 2018 milestone Jun 5, 2018
simaishi pushed a commit that referenced this pull request Jun 21, 2018
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit a1062535ada05bcdb39c6194e30a64f647d32044
Author: Keenan Brock <keenan@thebrocks.net>
Date:   Tue Jun 5 10:54:24 2018 -0400

    Merge pull request #17511 from NickLaMuro/ancestry_memoization_fixes
    
    Ancestry Patch updates/fixes
    (cherry picked from commit c6a6bedd2a09df590eb7fec6657bad08389b0296)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1593798

@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 3f6b2709f0a6095908c8a83cc685284eaa0feb9a
Author: Keenan Brock <keenan@thebrocks.net>
Date:   Tue Jun 5 10:54:24 2018 -0400

    Merge pull request #17511 from NickLaMuro/ancestry_memoization_fixes
    
    Ancestry Patch updates/fixes
    (cherry picked from commit c6a6bedd2a09df590eb7fec6657bad08389b0296)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1593797

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