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

Eliminate redundant token joining and const_get calls #2655

Merged
merged 5 commits into from
Dec 11, 2023

Conversation

joshcooper
Copy link
Contributor

@joshcooper joshcooper commented Dec 8, 2023

While working on a spike to fix dotted notation, I noticed the following:

  • Join query tokens once, not once per loaded fact
  • loaded_facts_hash is actually an Array, rename to loaded_facts
  • Refactor wildcard matching
  • Call Module#const_get once per Module
  • Added data flow doc

https://github.com/puppetlabs/facter/blob/1fbfe5c5dc8ca69b2c3e53823be0af9f2f6a5a4d/docs/data-flow.md

When searching for loaded facts that match the user query, we were joining the
query tokens once per loaded fact. For example, if the user query was
`networking.interfaces.eth0`, then we split the query into tokens ['networking',
'interfaces', 'eth0']. Then for each loaded fact definition, we joined the query
tokens back to 'networking.interfaces.eth0`. If none matched, then we tried
again using the parent prefix ['networking', 'interfaces'], again joining for
each loaded fact.

Now only join the query tokens once outside of the method.
Rename loaded_facts_hash and loaded_fact to loaded_facts
@joshcooper joshcooper requested a review from a team as a code owner December 8, 2023 22:21
docs/data-flow.md Outdated Show resolved Hide resolved
@mhashizume
Copy link
Contributor

Nit, but the wording of the commit message for ba58f16 seems like it has some editing artifacts in it

@joshcooper
Copy link
Contributor Author

joshcooper commented Dec 9, 2023

seems like it has some editing artifacts in it

I updated this, hopefully it's clearer?

@joshcooper
Copy link
Contributor Author

Oh wait I see, I’ll fix that

It's wasn't super obvious, but if `fact_with_wildcard` was true, then we
returned true or false depending on whether query_fact didn't match the fact
name exactly or not. Refactor the code to make it explicit.

Some more context, some legacy facts are dynamically generated and their names
contain wildcards, such as the `blockdevice_.*_model` legacy fact. If the user
queries for `blockdevice_sda_model` specifically, then we need to return the
legacy fact. In that case `fact_with_wildcard` will be true and the fact and
query names match exactly, so `found_fact?` will return true.

However, if you query for the similarly named structured fact
`blockdevice.sda.model`, then `fact_with_wildcard` will be false, since we want
to return the structured fact, not the legacy one.
@joshcooper joshcooper added the bug Something isn't working label Dec 11, 2023
@mhashizume mhashizume merged commit 69b0978 into puppetlabs:main Dec 11, 2023
17 checks passed
@joshcooper joshcooper deleted the perf_improvements branch December 11, 2023 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants