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

RUST-1764 Drop human_readable options in favor of HumanReadable #1064

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/action/find_and_modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
UpdateOrReplace,
},
options::WriteConcern,
serde_util,
ClientSession,
Collection,
};
Expand Down Expand Up @@ -105,10 +104,7 @@ impl<T: Serialize + DeserializeOwned + Send + Sync> Collection<T> {
FindOneAndReplace {
coll: self,
filter,
replacement: serde_util::to_raw_document_buf_with_options(
replacement.borrow(),
self.human_readable_serialization(),
),
replacement: bson::to_raw_document_buf(replacement.borrow()).map_err(Into::into),
options: None,
session: None,
}
Expand Down
4 changes: 1 addition & 3 deletions src/action/insert_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
operation::Insert as Op,
options::WriteConcern,
results::InsertManyResult,
serde_util,
ClientSession,
Collection,
};
Expand All @@ -30,12 +29,11 @@ impl<T: Serialize + Send + Sync> Collection<T> {
/// `await` will return d[`Result<InsertManyResult>`].
#[deeplink]
pub fn insert_many(&self, docs: impl IntoIterator<Item = impl Borrow<T>>) -> InsertMany {
let human_readable = self.human_readable_serialization();
InsertMany {
coll: CollRef::new(self),
docs: docs
.into_iter()
.map(|v| serde_util::to_raw_document_buf_with_options(v.borrow(), human_readable))
.map(|v| bson::to_raw_document_buf(v.borrow()).map_err(Into::into))
.collect(),
options: None,
session: None,
Expand Down
6 changes: 1 addition & 5 deletions src/action/insert_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
operation::Insert as Op,
options::WriteConcern,
results::InsertOneResult,
serde_util,
ClientSession,
Collection,
};
Expand All @@ -32,10 +31,7 @@ impl<T: Serialize + Send + Sync> Collection<T> {
pub fn insert_one(&self, doc: impl Borrow<T>) -> InsertOne {
InsertOne {
coll: CollRef::new(self),
doc: serde_util::to_raw_document_buf_with_options(
doc.borrow(),
self.human_readable_serialization(),
),
doc: bson::to_raw_document_buf(doc.borrow()).map_err(Into::into),
options: None,
session: None,
}
Expand Down
6 changes: 1 addition & 5 deletions src/action/replace_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
operation::Update as Op,
options::WriteConcern,
results::UpdateResult,
serde_util,
ClientSession,
Collection,
};
Expand All @@ -31,10 +30,7 @@ impl<T: Serialize + Send + Sync> Collection<T> {
ReplaceOne {
coll: CollRef::new(self),
query,
replacement: serde_util::to_raw_document_buf_with_options(
replacement.borrow(),
self.human_readable_serialization(),
),
replacement: bson::to_raw_document_buf(replacement.borrow()).map_err(Into::into),
options: None,
session: None,
}
Expand Down
8 changes: 0 additions & 8 deletions src/coll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ struct CollectionInner {
selection_criteria: Option<SelectionCriteria>,
read_concern: Option<ReadConcern>,
write_concern: Option<WriteConcern>,
human_readable_serialization: bool,
}

impl<T> Collection<T>
Expand All @@ -119,8 +118,6 @@ where
let write_concern = options
.write_concern
.or_else(|| db.write_concern().cloned());
#[allow(deprecated)]
let human_readable_serialization = options.human_readable_serialization.unwrap_or_default();

Self {
inner: Arc::new(CollectionInner {
Expand All @@ -130,7 +127,6 @@ where
selection_criteria,
read_concern,
write_concern,
human_readable_serialization,
}),
_phantom: Default::default(),
}
Expand Down Expand Up @@ -213,10 +209,6 @@ where
self.client().execute_operation(op, None).await?;
Ok(())
}

pub(crate) fn human_readable_serialization(&self) -> bool {
self.inner.human_readable_serialization
}
}

/// A struct modeling the canonical name for a collection in MongoDB.
Expand Down
9 changes: 0 additions & 9 deletions src/coll/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::{
// field or struct doesn't fix it because that annotation isn't propagated by the code generator.
// This works around that by defining it in a non-pub module and immediately re-exporting that
// module's contents.
#[allow(deprecated)]
mod suppress_warning {
use super::*;

Expand All @@ -36,14 +35,6 @@ mod suppress_warning {

/// The default write concern for operations.
pub write_concern: Option<WriteConcern>,

/// Sets the [`bson::SerializerOptions::human_readable`] option for the [`Bson`]
/// serializer. The default value is `false`.
/// Note: Specifying `true` for this value will decrease the performance of insert
/// operations.
#[deprecated = "This is a workaround for a potential bug related to RUST-1687, and should \
not be used in new code."]
pub human_readable_serialization: Option<bool>,
}
}
pub use suppress_warning::*;
Expand Down
19 changes: 1 addition & 18 deletions src/serde_util.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::time::Duration;

use bson::SerializerOptions;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use crate::{
bson::{doc, Bson, Document, RawDocumentBuf},
bson::{doc, Bson, Document},
bson_util::get_u64,
error::{Error, Result},
options::WriteConcern,
Expand Down Expand Up @@ -162,22 +161,6 @@ where
Ok(Some(date_time))
}

pub(crate) fn to_raw_document_buf_with_options<T: Serialize>(
doc: &T,
human_readable_serialization: bool,
) -> Result<RawDocumentBuf> {
let raw_doc = if human_readable_serialization {
let doc = bson::to_document_with_options(
doc,
SerializerOptions::builder().human_readable(true).build(),
)?;
RawDocumentBuf::from_document(&doc)?
} else {
bson::to_raw_document_buf(doc)?
};
Ok(raw_doc)
}

pub(crate) fn write_concern_is_empty(write_concern: &Option<WriteConcern>) -> bool {
write_concern
.as_ref()
Expand Down
28 changes: 9 additions & 19 deletions src/test/coll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
Client,
Namespace,
};
use bson::{rawdoc, RawDocumentBuf};
use bson::{rawdoc, serde_helpers::HumanReadable, RawDocumentBuf};
use futures::stream::{StreamExt, TryStreamExt};
use once_cell::sync::Lazy;
use semver::VersionReq;
Expand Down Expand Up @@ -1159,13 +1159,8 @@ async fn configure_human_readable_serialization() {

let client = TestClient::new().await;

let collection_options = CollectionOptions::builder()
.human_readable_serialization(false)
.build();

let non_human_readable_collection: Collection<Data> = client
.database("db")
.collection_with_options("nonhumanreadable", collection_options);
let non_human_readable_collection: Collection<Data> =
client.database("db").collection("nonhumanreadable");
non_human_readable_collection.drop().await.unwrap();

non_human_readable_collection
Expand Down Expand Up @@ -1204,20 +1199,15 @@ async fn configure_human_readable_serialization() {
.unwrap();
assert!(doc.get_binary_generic("s").is_ok());

let collection_options = CollectionOptions::builder()
.human_readable_serialization(true)
.build();

let human_readable_collection: Collection<Data> = client
.database("db")
.collection_with_options("humanreadable", collection_options);
let human_readable_collection: Collection<HumanReadable<Data>> =
client.database("db").collection("humanreadable");
human_readable_collection.drop().await.unwrap();

human_readable_collection
.insert_one(Data {
.insert_one(HumanReadable(Data {
id: 0,
s: StringOrBytes("human readable!".into()),
})
}))
.await
.unwrap();

Expand All @@ -1231,10 +1221,10 @@ async fn configure_human_readable_serialization() {
human_readable_collection
.replace_one(
doc! { "id": 0 },
Data {
HumanReadable(Data {
id: 1,
s: StringOrBytes("human readable!".into()),
},
}),
)
.await
.unwrap();
Expand Down
2 changes: 0 additions & 2 deletions src/test/spec/unified_runner/test_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,11 @@ impl CollectionOrDatabaseOptions {
}
}

#[allow(deprecated)]
pub(crate) fn as_collection_options(&self) -> CollectionOptions {
CollectionOptions {
read_concern: self.read_concern.clone(),
selection_criteria: self.selection_criteria.clone(),
write_concern: self.write_concern.clone(),
human_readable_serialization: None,
}
}
}
Expand Down