From 54185f8879625569838c0fda3cd91d54fd3dcd3f Mon Sep 17 00:00:00 2001 From: drshika <67125579+drshika@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:58:33 -0400 Subject: [PATCH] resolve remaining comments --- src/db.rs | 37 ++++++++++++----------- src/db/options.rs | 4 +-- src/operation/run_cursor_command.rs | 46 ++++++++++++++++------------- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/db.rs b/src/db.rs index c17eab749..785b0669a 100644 --- a/src/db.rs +++ b/src/db.rs @@ -2,9 +2,9 @@ pub mod options; use std::{fmt::Debug, sync::Arc}; -use futures_util::TryStreamExt; #[cfg(feature = "in-use-encryption-unstable")] use futures_util::stream::TryStreamExt; +use futures_util::TryStreamExt; use crate::{ bson::{Bson, Document}, @@ -15,9 +15,9 @@ use crate::{ ChangeStream, }, client::session::TransactionState, - cmap::{conn::PinnedConnectionHandle}, + cmap::conn::PinnedConnectionHandle, concern::{ReadConcern, WriteConcern}, - cursor::{Cursor}, + cursor::Cursor, error::{Error, ErrorKind, Result}, gridfs::{options::GridFsBucketOptions, GridFsBucket}, operation::{ @@ -482,10 +482,14 @@ impl Database { pub async fn run_cursor_command( &self, command: Document, - options: RunCursorCommandOptions, + options: impl Into>, ) -> Result> { - let rcc = RunCommand::new(self.name().to_string(), command, options.selection_criteria.clone(), None)?; - let rc_command = RunCursorCommand::new(rcc, options)?; + let options: Option = options.into().clone(); + let selection_criteria = options + .as_ref() + .and_then(|options| options.selection_criteria.clone()); + let rcc = RunCommand::new(self.name().to_string(), command, selection_criteria, None)?; + let rc_command = RunCursorCommand::new(rcc, options)?; let client = self.client(); client.execute_cursor_operation(rc_command).await } @@ -497,20 +501,17 @@ impl Database { options: impl Into>, session: &mut ClientSession, ) -> Result> { - let mut options: Option = options.into().clone(); + let mut options: Option = options.into(); resolve_selection_criteria_with_session!(self, options, Some(&mut *session))?; - let selection_criteria = match options.clone() { - Some(options) => options.selection_criteria, - None => None, - }; - let option = match options.clone() { - Some(options) => options, - None => RunCursorCommandOptions::default(), - }; + let selection_criteria = options + .as_ref() + .and_then(|options| options.selection_criteria.clone()); let rcc = RunCommand::new(self.name().to_string(), command, selection_criteria, None)?; - let rc_command = RunCursorCommand::new(rcc, option)?; + let rc_command = RunCursorCommand::new(rcc, options)?; let client = self.client(); - client.execute_session_cursor_operation(rc_command, session).await + client + .execute_session_cursor_operation(rc_command, session) + .await } /// Runs a database-level command using the provided `ClientSession`. @@ -650,4 +651,4 @@ impl Database { pub fn gridfs_bucket(&self, options: impl Into>) -> GridFsBucket { GridFsBucket::new(self.clone(), options.into().unwrap_or_default()) } -} \ No newline at end of file +} diff --git a/src/db/options.rs b/src/db/options.rs index 66c46cd4c..13302a714 100644 --- a/src/db/options.rs +++ b/src/db/options.rs @@ -9,7 +9,7 @@ use crate::{ bson::{Bson, Document}, concern::{ReadConcern, WriteConcern}, options::{Collation, CursorType}, - selection_criteria::{SelectionCriteria}, + selection_criteria::SelectionCriteria, serde_util, }; @@ -331,4 +331,4 @@ pub struct RunCursorCommandOptions { /// Optional BSON value. Use this value to configure the comment option sent on subsequent /// getMore commands. pub comment: Option, -} \ No newline at end of file +} diff --git a/src/operation/run_cursor_command.rs b/src/operation/run_cursor_command.rs index 65f58bcac..7547a374c 100644 --- a/src/operation/run_cursor_command.rs +++ b/src/operation/run_cursor_command.rs @@ -1,37 +1,29 @@ - - #[cfg(feature = "in-use-encryption-unstable")] use bson::doc; use bson::RawDocumentBuf; - use crate::{ cmap::{conn::PinnedConnectionHandle, Command, RawCommandResponse, StreamDescription}, - concern::{WriteConcern}, - cursor::{CursorSpecification}, + concern::WriteConcern, + cursor::CursorSpecification, error::{Error, Result}, - operation::{ - Operation, - RunCommand, - }, - options::{ - RunCursorCommandOptions, - }, + operation::{Operation, RunCommand}, + options::RunCursorCommandOptions, selection_criteria::SelectionCriteria, }; #[derive(Debug, Clone)] pub(crate) struct RunCursorCommand<'conn> { run_command: RunCommand<'conn>, - options: RunCursorCommandOptions, + options: Option, } -impl<'conn> RunCursorCommand<'conn>{ - pub(crate) fn new ( +impl<'conn> RunCursorCommand<'conn> { + pub(crate) fn new( run_command: RunCommand<'conn>, - options: RunCursorCommandOptions, + options: Option, ) -> Result { - Ok(Self{ + Ok(Self { run_command, options, }) @@ -106,12 +98,24 @@ impl<'conn> Operation for RunCursorCommand<'conn> { ) -> Result { let doc = Operation::handle_response(&self.run_command, response, description)?; let cursor_info = bson::from_document(doc)?; + let batch_size = match &self.options { + Some(options) => options.batch_size.clone(), + None => None, + }; + let max_time = match &self.options { + Some(options) => options.max_time.clone(), + None => None, + }; + let comment = match &self.options { + Some(options) => options.comment.clone(), + None => None, + }; Ok(CursorSpecification::new( cursor_info, description.server_address.clone(), - self.options.batch_size, - self.options.max_time, - self.options.comment.clone(), + batch_size, + max_time, + comment, )) } -} \ No newline at end of file +}