Skip to content

Commit e825cdf

Browse files
authored
Update mod.rs
1 parent 12d4ee9 commit e825cdf

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/pg/mod.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use crate::stmt_cache::{PrepareCallback, StmtCache};
1111
use crate::{AnsiTransactionManager, AsyncConnection, SimpleAsyncConnection};
1212
use diesel::connection::statement_cache::{PrepareForCache, StatementCacheKey};
1313
use diesel::pg::{
14-
Pg, PgMetadataCache, PgMetadataCacheKey, PgMetadataLookup, PgQueryBuilder,
15-
PgTypeMetadata,
14+
Pg, PgMetadataCache, PgMetadataCacheKey, PgMetadataLookup, PgQueryBuilder, PgTypeMetadata,
1615
};
1716
use diesel::query_builder::bind_collector::RawBytesBindCollector;
1817
use diesel::query_builder::{AsQuery, QueryBuilder, QueryFragment, QueryId};
@@ -367,32 +366,34 @@ impl AsyncPgConnection {
367366
//
368367
// We apply this workaround to prevent requiring all the diesel
369368
// serialization code to beeing async
370-
let mut dummy_lookup = SameOidEveryTime {
371-
first_byte: 0,
372-
};
373369
let mut bind_collector_0 = RawBytesBindCollector::<diesel::pg::Pg>::new();
374-
let collect_bind_result_0 = query.collect_binds(&mut bind_collector_0, &mut dummy_lookup, &Pg);
370+
let collect_bind_result_0 = query.collect_binds(
371+
&mut bind_collector_0,
372+
&mut SameOidEveryTime { first_byte: 0 },
373+
&Pg,
374+
);
375375

376-
dummy_lookup.first_byte = 1;
377376
let mut bind_collector_1 = RawBytesBindCollector::<diesel::pg::Pg>::new();
378-
let collect_bind_result_1 = query.collect_binds(&mut bind_collector_1, &mut dummy_lookup, &Pg);
377+
let collect_bind_result_1 = query.collect_binds(
378+
&mut bind_collector_1,
379+
&mut SameOidEveryTime { first_byte: 1 },
380+
&Pg,
381+
);
379382

380-
let mut metadata_lookup = PgAsyncMetadataLookup::new(&bind_collector_0.metadata);
381-
let collect_bind_result = query.collect_binds(&mut bind_collector, &mut metadata_lookup, &Pg);
382-
//dbg!(&bind_collector.binds);
383-
//dbg!(&bind_collector_0.binds);
384-
//dbg!(&bind_collector_1.binds);
383+
let mut metadata_lookup = PgAsyncMetadataLookup::new(&bind_collector_0);
384+
let collect_bind_result =
385+
query.collect_binds(&mut bind_collector, &mut metadata_lookup, &Pg);
385386

386387
let fake_oid_locations = std::iter::zip(bind_collector_0.binds, bind_collector_1.binds)
387388
.enumerate()
388389
.flat_map(|(bind_index, (bytes_0, bytes_1))| {
389390
std::iter::zip(bytes_0.unwrap_or_default(), bytes_1.unwrap_or_default())
390391
.enumerate()
391-
.filter_map(move |(byte_index, bytes)| (bytes == (0, 1)).then_some((bind_index, byte_index)))
392+
.filter(|(_, bytes)| bytes == (0, 1))
393+
.map(|(byte_index, _)| (*bind_index, byte_index))
392394
})
393395
// Avoid storing the bind collectors in the returned Future
394396
.collect::<Vec<_>>();
395-
//dbg!(&fake_oid_locations);
396397

397398
let raw_connection = self.conn.clone();
398399
let stmt_cache = self.stmt_cache.clone();
@@ -436,10 +437,10 @@ impl AsyncPgConnection {
436437
};
437438
let (fake_oid, fake_array_oid) = metadata_lookup.fake_oids(index);
438439
let [real_oid, real_array_oid] = unwrap_oids(&real_metadata);
439-
real_oids.extend(dbg!([
440+
real_oids.extend([
440441
(fake_oid, real_oid),
441442
(fake_array_oid, real_array_oid),
442-
]));
443+
]);
443444
}
444445

445446
// Replace fake OIDs with real OIDs in `bind_collector.metadata`
@@ -452,7 +453,7 @@ impl AsyncPgConnection {
452453
// If `oid` is not a key in `real_oids`, then `HasSqlType::metadata` returned it as a
453454
// hardcoded value instead of being lied to by `PgAsyncMetadataLookup`. In this case,
454455
// the existing value is already the real OID, so it's kept.
455-
.unwrap_or_else(|| dbg!(oid))
456+
.unwrap_or(oid)
456457
});
457458
*m = PgTypeMetadata::new(oid, array_oid);
458459
}
@@ -510,8 +511,9 @@ struct PgAsyncMetadataLookup {
510511
}
511512

512513
impl PgAsyncMetadataLookup {
513-
fn new(metadata_0: &[PgTypeMetadata]) -> Self {
514-
let max_hardcoded_oid = metadata_0
514+
fn new(bind_collector_0: &RawBytesBindCollector<Pg>) -> Self {
515+
let max_hardcoded_oid = bind_collector_0
516+
.metadata
515517
.iter()
516518
.flat_map(|m| [m.oid().unwrap_or(0), m.array_oid().unwrap_or(0)])
517519
.max()
@@ -533,7 +535,6 @@ impl PgMetadataLookup for PgAsyncMetadataLookup {
533535
let index = self.unresolved_types.len();
534536
self.unresolved_types
535537
.push((schema.map(ToOwned::to_owned), type_name.to_owned()));
536-
dbg!(index, self.fake_oids(index));
537538
PgTypeMetadata::from_result(Ok(self.fake_oids(index)))
538539
}
539540
}
@@ -598,7 +599,7 @@ fn replace_fake_oid(
598599
.as_mut()?
599600
.get_mut(byte_index..)?
600601
.first_chunk_mut::<4>()?;
601-
//*serialized_oid = real_oids.get(&u32::from_be_bytes(*serialized_oid))?.to_be_bytes();
602+
*serialized_oid = real_oids.get(&u32::from_be_bytes(*serialized_oid))?.to_be_bytes();
602603
Some(())
603604
}
604605

0 commit comments

Comments
 (0)