Byron / google-apis-rs

A binding and CLI generator for all Google APIs
http://byron.github.io/google-apis-rs
Other
1.01k stars 131 forks source link

Refactor client functions #371

Closed philippeitis closed 1 year ago

philippeitis commented 1 year ago

I'm not sure whether these changes should be included in the previous PR - but given that it's non-essential, I've decided to keep them separate.

The first change is refactoring remove_json_null_values to run in linear time (the arr.remove() call takes O(n) time and may be called n times, which could accidentally lead to quadratic run times) - this incidentally makes the code a lot cleaner.

The second change is using tokio::time::sleep in place of std::thread::sleep in the upload functions (for both google-apis-common and api.rs). std::thread::sleep is blocking per https://doc.rust-lang.org/stable/std/thread/fn.sleep.html, and should not be used in async functions.

Byron commented 1 year ago

Thanks a million for these fixes! Especially the thread::sleep one is a huge oversight that could make these crates unusable in a server context, a lingering time-bomb if you will.

Too bad I forgot about this PR when publishing previously, so maybe in future it's preferred to keep small fixes with unrelated PRs as my memory can't be trusted 😅.