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

Queue refactor #110

Merged
merged 13 commits into from
Dec 11, 2020
Merged

Queue refactor #110

merged 13 commits into from
Dec 11, 2020

Conversation

MindFlavor
Copy link
Contributor

Building on #109, this is a draft of the same changes on azure queue storage.

This PR follows the same patterns and proposes some new types (Timeout, ClienrtRequestId and Metadata), removes the trait functions (now simply struct functions) for the builder(s).

I am not happy with the Metadata struct so suggestions are welcome: for the time being it's a string owning hashmap but maybe a &str based one would be better? A Cow to give the user liberty to choose?

@MindFlavor MindFlavor requested a review from rylev December 3, 2020 16:54
Copy link
Contributor

@rylev rylev left a comment

Choose a reason for hiding this comment

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

Looking good so far. I have some small comments.

sdk/core/src/client_request_id.rs Outdated Show resolved Hide resolved
sdk/core/src/metadata.rs Show resolved Hide resolved
sdk/storage/src/queue/requests/create_queue_builder.rs Outdated Show resolved Hide resolved
@@ -86,7 +87,7 @@ where
url.as_str(),
&http::Method::PUT,
&|mut request| {
request = AddAsHeader::add_as_header(self.client_request_id(), request);
request = add_header(self.client_request_id(), request);
request = AddAsHeader::add_as_header(&self.metadata(), request);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not this one as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

metadata is not Option so we cannot use the helper function. Should we create a non option variant? I would be a one liner so I thought better to call the trait function directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's up to you. In cosmos I wrap the ones that are not options in Some. The compiler most likely can see through this and will skip the if check add_header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think than using wrapping into a fake Option for the sake of saving a function makes for confusing code.

I suggest we have two functions instead: add_optional_header and add_mandatory_header. Their names are self-explanatory even to a casual reader.

@MindFlavor MindFlavor marked this pull request as ready for review December 4, 2020 16:07
req = crate::headers::add_header(Some(self.is_upsert()), req);
req = crate::headers::add_header(Some(self.indexing_directive()), req);
req = crate::headers::add_header(Some(self.allow_tentative_writes()), req);
req = azure_core::headers::add_optional_header(&self.if_match_condition(), req);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is better.

@MindFlavor MindFlavor mentioned this pull request Dec 5, 2020
4 tasks
Copy link
Contributor

@rylev rylev left a comment

Choose a reason for hiding this comment

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

I really love the direction of this PR, but I'd like to see some of the old cruft that's no longer used deleted, and I still see some things that are more complicated than they need to be.

sdk/core/src/client_request_id.rs Outdated Show resolved Hide resolved
sdk/core/src/headers/mod.rs Show resolved Hide resolved
use std::collections::HashMap;

#[derive(Debug, Clone)]
pub struct Metadata<'a>(HashMap<Cow<'a, str>, Cow<'a, str>>);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same point here about Cow. This makes the type harder to understand and thus harder to use.

Copy link
Contributor Author

@MindFlavor MindFlavor Dec 11, 2020

Choose a reason for hiding this comment

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

I am on the fence on whether to accept &str or a String. &str means the Metadata struct cannot escape the owning function easily while forcing string means potentially copying hundreds of strings around (unlikely though).

I'll go with String for ergonomics.

Copy link
Contributor

Choose a reason for hiding this comment

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

For everything else we're taking &str. I'm fine with going with String. We might want to think about why Metadata is special and takes String. Perhaps more types should take String instead of &str. Something to think about....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning is: for something that does not make sense outside a request (like client_request_id) &str is fine. This is because you use it on a request only, and a requests are short lived 99% of the time (so borrowing makes sense).

For everything else String is better.

sdk/core/src/metadata.rs Outdated Show resolved Hide resolved
sdk/core/src/modify_conditions.rs Show resolved Hide resolved
sdk/storage/examples/queue_create.rs Show resolved Hide resolved
sdk/storage/examples/queue_create.rs Show resolved Hide resolved
sdk/storage/src/queue/requests/get_messages_builder.rs Outdated Show resolved Hide resolved
sdk/core/src/prelude.rs Show resolved Hide resolved
@rylev rylev merged commit 6cf3be4 into master Dec 11, 2020
@rylev rylev deleted the queue_refactor branch December 11, 2020 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants