facebook / watchman

Watches files and records, or triggers actions, when they change.
https://facebook.github.io/watchman/
MIT License
12.4k stars 987 forks source link

Implement `maximum_results` option #1215

Open yamadapc opened 2 months ago

yamadapc commented 2 months ago

When working on large mono-repos some queries might take a very long time due to listing all files on the project.

This waiting time is a combination of building the results array and serialising it back.

This commit adds a query option maximum_results, which allows clients to ask the server to truncate results above a certain threshold number.

On that case, a flag is sent back indicating to the client results have been truncated.

We could change this diff to read this value as a global setting rather than a per request setting. But then for any given instance we'd need to globally assume the setting is handled correctly, which may not be the case.

I still need to test direct BSER clients against this change.

I'd appreciate an opinion on the diff & where to write automated tests for this. I don't see unit-testing around this area, so I imagine those would be integration tests.

facebook-github-bot commented 2 months ago

Hi @yamadapc!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

facebook-github-bot commented 2 months ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

yamadapc commented 2 months ago

Hello, could I get an opinion on this diff?

yamadapc commented 1 month ago

Hey :wave:

genevievehelsel commented 1 month ago

Hey 👋

followed up in the Sapling discord (nice idea asking there :) ) but copy-pasting here for wider visibility:

hi from the watchman team - I think this looks like a good idea 🙂 we've got a similar flag like @quark-zju mentioned for a watcher we use often (watcher/eden.cpp) for the same reasons you mentioned in your summary

on the making the eden_file_count_threshold_for_fresh_instannce more universal, the code pointer for that is here:

https://github.com/facebook/watchman/blob/main/watchman/watcher/eden.cpp#L760

It would be a lot cleaner IMO if we could just leverage the existing fresh_instance code for this, in a similar manner to how its done for the eden watcher, especially since some clients might already know how to handle fresh instances and they'd have to relearn how to handle a new flag if they wanted to use this feature

we have an integration test for this flag for the eden watcher here: https://github.com/facebook/watchman/blob/main/watchman/integration/eden/test_eden_since.py#L296

if you went the route of returning fresh instances if threshold is reached, you could just make a similar test to the above but for a non-eden watcher 🙂