@@ -20,17 +20,21 @@ public static async ValueTask<MySqlDataReader> ExecuteReaderAsync(CommandListPos
20
20
21
21
Log . CommandExecutorExecuteReader ( command . Logger , connection . Session . Id , ioBehavior , commandListPosition . CommandCount ) ;
22
22
23
- Dictionary < string , CachedProcedure ? > ? cachedProcedures = null ;
23
+ var cachedProcedures = new Dictionary < string , CachedProcedure ? > ( ) ;
24
24
for ( var commandIndex = 0 ; commandIndex < commandListPosition . CommandCount ; commandIndex ++ )
25
25
{
26
26
var command2 = commandListPosition . CommandAt ( commandIndex ) ;
27
- if ( command2 . CommandType == CommandType . StoredProcedure )
27
+ if ( command2 . CommandType == CommandType . StoredProcedure && connection . Session . UseProcedureCache )
28
28
{
29
- cachedProcedures ??= [ ] ;
30
29
var commandText = command2 . CommandText ! ;
31
30
if ( ! cachedProcedures . ContainsKey ( commandText ) )
32
31
{
33
- cachedProcedures . Add ( commandText , await connection . GetCachedProcedure ( commandText , revalidateMissing : false , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ) ;
32
+ var cachedProcedure = await connection . GetCachedProcedure ( commandText , revalidateMissing : false , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
33
+
34
+ if ( cachedProcedure != null )
35
+ {
36
+ cachedProcedures . Add ( commandText , cachedProcedure ) ;
37
+ }
34
38
35
39
// because the connection was used to execute a MySqlDataReader with the connection's DefaultCommandTimeout,
36
40
// we need to reapply the command's CommandTimeout (even if some of the time has elapsed)
@@ -41,7 +45,7 @@ public static async ValueTask<MySqlDataReader> ExecuteReaderAsync(CommandListPos
41
45
42
46
var writer = new ByteBufferWriter ( ) ;
43
47
//// cachedProcedures will be non-null if there is a stored procedure, which is also the only time it will be read
44
- if ( ! payloadCreator . WriteQueryCommand ( ref commandListPosition , cachedProcedures ! , writer , false ) )
48
+ if ( ! payloadCreator . WriteQueryCommand ( ref commandListPosition , cachedProcedures , writer , false ) )
45
49
throw new InvalidOperationException ( "ICommandPayloadCreator failed to write query payload" ) ;
46
50
47
51
cancellationToken . ThrowIfCancellationRequested ( ) ;
0 commit comments