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

[WIP] Remove <value> nodes from MiqExpression#to_ruby #23104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Jul 23, 2024

Overview

For now, this is only changes simple expressions like Host-name and not those with an association Vm.host-name.
It also does not change <find> clauses.

Looking for feedback on whether this is a good route. (I'm happy to merge code)

exp = MiqExpression.new({"=" => {"field" => "Vm-platform", "value" => "foo"}})
tmp_ruby_exp = exp.to_ruby
records.select do |rec|
  ruby_exp = Condition.subst(tmp_ruby_exp, rec)
  # Condition.do_eval(ruby_exp, rec)
  eval(ruby_exp)
end

Before

# to_ruby produces psudo ruby
tmp_ruby_exp = "!(<value ref=vm, type=string>/virtual/platform</value> == \"foo\"")
# for each record, `subst` runs `tmp_ruby_exp.gsub(/<value/>/, rec.platform)`.
ruby_exp = "!(\"windows\" == \"foo\")"
# eval = false

After

# to_ruby produces pseudo ruby
tmp_ruby_exp = "!(rec.platform == \"foo\")"
# subst is a noop
ruby_exp = "!(rec.platform == \"foo\")"
# eval = false

@kbrock
Copy link
Member Author

kbrock commented Jul 24, 2024

@Fryguy When @jrafanie was working through performance for MiqExpression (in the api?), we saw a lot of time spent in subst on large record sets.

So I had started modifying subst but realized modifying to_ruby to not producing the <value> in the first place was a lot easier than untangling the code in subst.

Got a little bit of a wrench for the "hash" mode. It is used in 2 spots for the reports and the ui. Wondering why we need a whole separate encoding scheme for that use case.

Question: Do you feel this is a good direction or too much of a tangent?
If so, I can fix the spec and style

@kbrock kbrock changed the title Miq expression subst Remove <value> nodes from MiqExpression#to_ruby Jul 24, 2024
@kbrock kbrock changed the title Remove <value> nodes from MiqExpression#to_ruby [WIP] Remove <value> nodes from MiqExpression#to_ruby Jul 24, 2024
@miq-bot miq-bot added the wip label Jul 24, 2024
@miq-bot miq-bot added the stale label Nov 1, 2024
@miq-bot
Copy link
Member

miq-bot commented Nov 1, 2024

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

This allows us to use `rec` in the expression and not have to
post evaluate the to_ruby output

Skipped over the associations and the find clauses
Also skipped the hash contexts
@miq-bot
Copy link
Member

miq-bot commented Nov 6, 2024

Some comments on commits kbrock/manageiq@12d5b91~...e9d9f18

spec/lib/miq_expression_spec.rb

  • ⚠️ - 1519 - Detected puts. Remove all debugging statements.
  • ⚠️ - 1526 - Detected puts. Remove all debugging statements.
  • ⚠️ - 1533 - Detected puts. Remove all debugging statements.
  • ⚠️ - 1575 - Detected puts. Remove all debugging statements.
  • ⚠️ - 1582 - Detected puts. Remove all debugging statements.
  • ⚠️ - 1589 - Detected puts. Remove all debugging statements.

@miq-bot
Copy link
Member

miq-bot commented Nov 6, 2024

Checked commits kbrock/manageiq@12d5b91~...e9d9f18 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
7 files checked, 7 offenses detected

app/models/condition.rb

lib/miq_expression.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.

4 participants