@@ -11,8 +11,7 @@ use crate::stmt_cache::{PrepareCallback, StmtCache};
11
11
use crate :: { AnsiTransactionManager , AsyncConnection , SimpleAsyncConnection } ;
12
12
use diesel:: connection:: statement_cache:: { PrepareForCache , StatementCacheKey } ;
13
13
use diesel:: pg:: {
14
- Pg , PgMetadataCache , PgMetadataCacheKey , PgMetadataLookup , PgQueryBuilder ,
15
- PgTypeMetadata ,
14
+ Pg , PgMetadataCache , PgMetadataCacheKey , PgMetadataLookup , PgQueryBuilder , PgTypeMetadata ,
16
15
} ;
17
16
use diesel:: query_builder:: bind_collector:: RawBytesBindCollector ;
18
17
use diesel:: query_builder:: { AsQuery , QueryBuilder , QueryFragment , QueryId } ;
@@ -367,32 +366,34 @@ impl AsyncPgConnection {
367
366
//
368
367
// We apply this workaround to prevent requiring all the diesel
369
368
// serialization code to beeing async
370
- let mut dummy_lookup = SameOidEveryTime {
371
- first_byte : 0 ,
372
- } ;
373
369
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
+ ) ;
375
375
376
- dummy_lookup. first_byte = 1 ;
377
376
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
+ ) ;
379
382
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 ) ;
385
386
386
387
let fake_oid_locations = std:: iter:: zip ( bind_collector_0. binds , bind_collector_1. binds )
387
388
. enumerate ( )
388
389
. flat_map ( |( bind_index, ( bytes_0, bytes_1) ) | {
389
390
std:: iter:: zip ( bytes_0. unwrap_or_default ( ) , bytes_1. unwrap_or_default ( ) )
390
391
. 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) )
392
394
} )
393
395
// Avoid storing the bind collectors in the returned Future
394
396
. collect :: < Vec < _ > > ( ) ;
395
- //dbg!(&fake_oid_locations);
396
397
397
398
let raw_connection = self . conn . clone ( ) ;
398
399
let stmt_cache = self . stmt_cache . clone ( ) ;
@@ -436,10 +437,10 @@ impl AsyncPgConnection {
436
437
} ;
437
438
let ( fake_oid, fake_array_oid) = metadata_lookup. fake_oids ( index) ;
438
439
let [ real_oid, real_array_oid] = unwrap_oids ( & real_metadata) ;
439
- real_oids. extend ( dbg ! ( [
440
+ real_oids. extend ( [
440
441
( fake_oid, real_oid) ,
441
442
( fake_array_oid, real_array_oid) ,
442
- ] ) ) ;
443
+ ] ) ;
443
444
}
444
445
445
446
// Replace fake OIDs with real OIDs in `bind_collector.metadata`
@@ -452,7 +453,7 @@ impl AsyncPgConnection {
452
453
// If `oid` is not a key in `real_oids`, then `HasSqlType::metadata` returned it as a
453
454
// hardcoded value instead of being lied to by `PgAsyncMetadataLookup`. In this case,
454
455
// the existing value is already the real OID, so it's kept.
455
- . unwrap_or_else ( || dbg ! ( oid) )
456
+ . unwrap_or ( oid)
456
457
} ) ;
457
458
* m = PgTypeMetadata :: new ( oid, array_oid) ;
458
459
}
@@ -510,8 +511,9 @@ struct PgAsyncMetadataLookup {
510
511
}
511
512
512
513
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
515
517
. iter ( )
516
518
. flat_map ( |m| [ m. oid ( ) . unwrap_or ( 0 ) , m. array_oid ( ) . unwrap_or ( 0 ) ] )
517
519
. max ( )
@@ -533,7 +535,6 @@ impl PgMetadataLookup for PgAsyncMetadataLookup {
533
535
let index = self . unresolved_types . len ( ) ;
534
536
self . unresolved_types
535
537
. push ( ( schema. map ( ToOwned :: to_owned) , type_name. to_owned ( ) ) ) ;
536
- dbg ! ( index, self . fake_oids( index) ) ;
537
538
PgTypeMetadata :: from_result ( Ok ( self . fake_oids ( index) ) )
538
539
}
539
540
}
@@ -598,7 +599,7 @@ fn replace_fake_oid(
598
599
. as_mut ( ) ?
599
600
. get_mut ( byte_index..) ?
600
601
. 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 ( ) ;
602
603
Some ( ( ) )
603
604
}
604
605
0 commit comments