Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

fix: use find to infer fields COMPASS-4154 #232

Merged
merged 2 commits into from
Jan 26, 2021
Merged

Conversation

mcasimir
Copy link
Contributor

This is a pre-requisite to COMPASS-4154, since that contains a breaking change for import/export.

Rather than adapting this code to the new dataService.sample here we just switch back to a plain find, since in practice the accuracy is similar but the performance is better compared to a $sample aggregation.

@mcasimir mcasimir changed the title COMPASS-4154: use find to infer fields fix: use find to infer fields COMPASS-4154 Jan 25, 2021
Copy link
Member

@Anemy Anemy left a comment

Choose a reason for hiding this comment

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

lgtm - lots smoother and quicker
nice tests
I think it still could happen that on a slow connection there's a slight delay between when a user opens the fields panel and when it's populated, but it's not going to be based on anything except latency now.

@@ -164,7 +165,6 @@
"mime-types": "^2.1.24",
"mongodb-extjson": "^4.0.0-rc1",
"mongodb-query-parser": "^2.1.2",
"mongodb-schema": "^8.2.5",
Copy link
Member

Choose a reason for hiding this comment

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

🔥

const docs = await find(ns, filter || {}, {
limit: sampleSize || DEFAULT_SAMPLE_SIZE,
...driverOptions
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my own understanding, this will mean that if documents that are added to a collection after the first sampleSize documents will not affect the result here, and that we are okay with that?

Copy link
Contributor Author

@mcasimir mcasimir Jan 26, 2021

Choose a reason for hiding this comment

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

Yep, that is a great point.. I don't think we should be. Initially it was based on 1 document find, then on a random sample of 50 docs, which is a bit better but extremely slow on a big collection, causing the field selection dialog to be blank for a while without any indication, that's why we switched it to a 50 docs find.

The only accurate way to get all the fields is a full collection scan, otherwise we need to change approach: have a 'use all the fields option', relay on users building their own projections without the fields selection, let people decide how many documents to scan to get the fields or at least indicate fields are being loaded...

@mcasimir mcasimir merged commit a1eb523 into master Jan 26, 2021
@mcasimir mcasimir deleted the revert-COMPASS-4449 branch January 26, 2021 09:41
@addaleax
Copy link
Contributor

addaleax commented Feb 1, 2021

Did this cause https://jira.mongodb.org/browse/COMPASS-4593?

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

Successfully merging this pull request may close these issues.

3 participants