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

Minor cleanup for #3213 #3236

Merged
merged 2 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 9 additions & 8 deletions diesel/src/pg/connection/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Iterator for Cursor {
/// Acts as an iterator over `T`.
#[allow(missing_debug_implementations)]
pub struct RowByRowCursor<'a> {
current_row: usize,
first_row: bool,
db_result: Rc<PgResult>,
conn: &'a mut super::ConnectionAndTransactionManager,
}
Expand All @@ -72,7 +72,7 @@ impl<'a> RowByRowCursor<'a> {
conn: &'a mut super::ConnectionAndTransactionManager,
) -> Self {
RowByRowCursor {
current_row: 0,
first_row: true,
db_result: Rc::new(db_result),
conn,
}
Expand All @@ -83,30 +83,31 @@ impl Iterator for RowByRowCursor<'_> {
type Item = crate::QueryResult<PgRow>;

fn next(&mut self) -> Option<Self::Item> {
if self.current_row > 0 {
if !self.first_row {
let get_next_result = super::update_transaction_manager_status(
self.conn.raw_connection.get_next_result(),
self.conn,
);
match get_next_result {
Ok(Some(res)) => {
// we try to reuse the existing allocation here
if let Some(old_res) = Rc::get_mut(&mut self.db_result) {
*old_res = res;
} else {
self.db_result = Rc::new(res);
}
self.current_row = 0;
}
Ok(None) => {
return None;
}
Err(e) => return Some(Err(e)),
}
}
if self.current_row < self.db_result.num_rows() {
let row = self.db_result.clone().get_row(self.current_row);
self.current_row += 1;
Some(Ok(row))
// This contains either 1 (for a row containing data) or 0 (for the last one) rows
if self.db_result.num_rows() > 0 {
debug_assert_eq!(self.db_result.num_rows(), 1);
self.first_row = false;
Some(Ok(self.db_result.clone().get_row(0)))
} else {
None
}
Expand Down
2 changes: 1 addition & 1 deletion diesel/src/pg/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::os::raw as libc;
///
/// Due to the fact that `PgConnection` supports multiple loading modes
/// it is **required** to always specify the used loading mode
/// when calling [`RunQueryDsl::load_iter`] or [`LoadConnection::load`].
/// when calling [`RunQueryDsl::load_iter`]
///
/// ## `DefaultLoadingMode`
///
Expand Down