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

[search source] Simplify / refactor flatten method - Part 2 #183206

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented May 11, 2024

Summary

Follow up to #183107 (should probably wait for that to be merged before reviewing this)

The SearchSource flatten method does a lot of object mutation and has a lot of long conditional statements. I'm breaking code out into functions and reducing the amount of object mutation. Changes to code logic have been kept minimal.

Part of #182068

@mattkime
Copy link
Contributor Author

/ci

5 similar comments
@mattkime
Copy link
Contributor Author

/ci

@mattkime
Copy link
Contributor Author

/ci

@mattkime
Copy link
Contributor Author

/ci

@mattkime
Copy link
Contributor Author

/ci

@mattkime
Copy link
Contributor Author

/ci

@mattkime mattkime self-assigned this May 12, 2024
// only include unique values
if (sourceFieldsProvided) {
if (!isEqual(remainingFields, fieldsFromSource)) {
setWith(body, '_source.includes', remainingFields, (nsValue) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is driving me crazy - this is object mutation code that I'd like to rewrite without object mutation but I'm having a very hard time figuring out how to do this.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is all extraneous and could just be replaced with

    if (sourceFieldsProvided && !isEqual(remainingFields, fieldsFromSource)) {
      body._source.includes = remainingFields;
    }

@mattkime mattkime changed the title Search source flatten refactor more [search source] Simplify / refactor flatten method - Part 2 May 12, 2024
@mattkime mattkime added Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) Feature:Search Querying infrastructure in Kibana release_note:skip Skip the PR/issue when compiling release notes labels May 12, 2024
@mattkime mattkime marked this pull request as ready for review May 12, 2024 22:46
@mattkime mattkime requested review from a team as code owners May 12, 2024 22:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@mattkime
Copy link
Contributor Author

/ci

1 similar comment
@mattkime
Copy link
Contributor Author

/ci

Copy link
Member

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

I think the readability improvements here are great! I wonder if we can do a little more to help the types from getting out of control - I know they were already bad to begin with, but I wonder if we can do something other than adding : any so many times. I want to give this a more thorough look tomorrow and hopefully have some helpful feedback as to how we can accomplish that.

// only include unique values
if (sourceFieldsProvided) {
if (!isEqual(remainingFields, fieldsFromSource)) {
setWith(body, '_source.includes', remainingFields, (nsValue) => {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is all extraneous and could just be replaced with

    if (sourceFieldsProvided && !isEqual(remainingFields, fieldsFromSource)) {
      body._source.includes = remainingFields;
    }

@mattkime
Copy link
Contributor Author

mattkime commented May 14, 2024

@lukasolson I agree it would be great to improve the types. My earlier attempts didn't go well but it might be easier at this point


I wonder if this is all extraneous and could just be replaced with

That doesn't work, at least not when I run the corresponding search_source.test.ts jest tests.

@mattkime
Copy link
Contributor Author

/ci

@lukasolson
Copy link
Member

That doesn't work, at least not when I run the corresponding search_source.test.ts jest tests.

This seems to work:

    // only include unique values
    if (sourceFieldsProvided && !isEqual(remainingFields, fieldsFromSource)) {
      body._source = { includes: remainingFields };
    }

@lukasolson
Copy link
Member

I took a stab at improving the types here: mattkime#21

@mattkime
Copy link
Contributor Author

/ci

@mattkime mattkime force-pushed the search_source_flatten_refactor_more branch from 2276689 to 4065282 Compare May 15, 2024 22:21
@mattkime
Copy link
Contributor Author

/ci

2 similar comments
@mattkime
Copy link
Contributor Author

/ci

@mattkime
Copy link
Contributor Author

/ci

@lukasolson lukasolson requested a review from a team as a code owner May 21, 2024 18:56
@lukasolson lukasolson requested review from a team as code owners May 21, 2024 18:56
@botelastic botelastic bot added the ci:project-deploy-observability Create an Observability project label May 21, 2024
Copy link
Contributor

@opauloh opauloh left a comment

Choose a reason for hiding this comment

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

cloud security changes ltgm

@mattkime
Copy link
Contributor Author

/ci

@mattkime mattkime force-pushed the search_source_flatten_refactor_more branch from 815cc33 to 2395f2a Compare May 25, 2024 18:43
@mattkime
Copy link
Contributor Author

/ci

@mattkime
Copy link
Contributor Author

/ci

@kibana-ci
Copy link
Collaborator

kibana-ci commented May 25, 2024

💚 Build Succeeded

Metrics [docs]

Canvas Sharable Runtime

The Canvas "shareable runtime" is an bundle produced to enable running Canvas workpads outside of Kibana. This bundle is included in third-party webpages that embed canvas and therefor should be as slim as possible.

id before after diff
module count - 5412 +5412
total size - 8.8MB +8.8MB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 419.0KB 419.0KB -2.0B
dataViews 61.6KB 61.7KB +123.0B
total +121.0B
Unknown metric groups

API count

id before after diff
dataViews 1156 1158 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @mattkime

@mattkime mattkime removed the request for review from a team May 26, 2024 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:review ci:project-deploy-observability Create an Observability project Feature:Search Querying infrastructure in Kibana release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants