@@ -1698,6 +1698,8 @@ bool QgsAuthManager::initSslCaches()
1698
1698
res = res && rebuildCertTrustCache ();
1699
1699
res = res && rebuildTrustedCaCertsCache ();
1700
1700
res = res && rebuildIgnoredSslErrorCache ();
1701
+ mCustomConfigByHostCache .clear ();
1702
+ mHasCheckedIfCustomConfigByHostExists = false ;
1701
1703
1702
1704
QgsDebugMsg ( QStringLiteral ( " Init of SSL caches %1" ).arg ( res ? " SUCCEEDED" : " FAILED" ) );
1703
1705
return res;
@@ -1994,6 +1996,8 @@ bool QgsAuthManager::storeSslCertCustomConfig( const QgsAuthConfigSslServer &con
1994
1996
.arg ( config.sslHostPort ().trimmed (), id ) );
1995
1997
1996
1998
updateIgnoredSslErrorsCacheFromConfig ( config );
1999
+ mHasCheckedIfCustomConfigByHostExists = false ;
2000
+ mCustomConfigByHostCache .clear ();
1997
2001
1998
2002
return true ;
1999
2003
}
@@ -2042,23 +2046,53 @@ const QgsAuthConfigSslServer QgsAuthManager::sslCertCustomConfig( const QString
2042
2046
2043
2047
const QgsAuthConfigSslServer QgsAuthManager::sslCertCustomConfigByHost ( const QString &hostport )
2044
2048
{
2045
- QMutexLocker locker ( mMutex );
2046
2049
QgsAuthConfigSslServer config;
2047
-
2048
2050
if ( hostport.isEmpty () )
2049
2051
{
2050
- QgsDebugMsg ( QStringLiteral ( " Passed host:port is empty" ) );
2051
2052
return config;
2052
2053
}
2053
2054
2055
+ QMutexLocker locker ( mMutex );
2056
+ if ( mHasCheckedIfCustomConfigByHostExists && !mHasCustomConfigByHost )
2057
+ return config;
2058
+ if ( mCustomConfigByHostCache .contains ( hostport ) )
2059
+ return mCustomConfigByHostCache .value ( hostport );
2060
+
2054
2061
QSqlQuery query ( authDatabaseConnection () );
2062
+
2063
+ // first run -- see if we have ANY custom config by host. If not, we can skip all future checks for any host
2064
+ if ( !mHasCheckedIfCustomConfigByHostExists )
2065
+ {
2066
+ mHasCheckedIfCustomConfigByHostExists = true ;
2067
+ query.prepare ( QString ( " SELECT count(*) FROM %1" ).arg ( authDatabaseServersTable () ) );
2068
+ if ( !authDbQuery ( &query ) )
2069
+ {
2070
+ mHasCustomConfigByHost = false ;
2071
+ return config;
2072
+ }
2073
+ if ( query.isActive () && query.isSelect () && query.first () )
2074
+ {
2075
+ mHasCustomConfigByHost = query.value ( 0 ).toInt () > 0 ;
2076
+ if ( !mHasCustomConfigByHost )
2077
+ return config;
2078
+ }
2079
+ else
2080
+ {
2081
+ mHasCustomConfigByHost = false ;
2082
+ return config;
2083
+ }
2084
+ }
2085
+
2055
2086
query.prepare ( QString ( " SELECT id, host, cert, config FROM %1 "
2056
2087
" WHERE host = :host" ).arg ( authDatabaseServersTable () ) );
2057
2088
2058
2089
query.bindValue ( QStringLiteral ( " :host" ), hostport.trimmed () );
2059
2090
2060
2091
if ( !authDbQuery ( &query ) )
2092
+ {
2093
+ mCustomConfigByHostCache .insert ( hostport, config );
2061
2094
return config;
2095
+ }
2062
2096
2063
2097
if ( query.isActive () && query.isSelect () )
2064
2098
{
@@ -2075,9 +2109,12 @@ const QgsAuthConfigSslServer QgsAuthManager::sslCertCustomConfigByHost( const QS
2075
2109
emit messageOut ( tr ( " Authentication database contains duplicate SSL cert custom configs for host:port: %1" )
2076
2110
.arg ( hostport ), authManTag (), WARNING );
2077
2111
QgsAuthConfigSslServer emptyconfig;
2112
+ mCustomConfigByHostCache .insert ( hostport, emptyconfig );
2078
2113
return emptyconfig;
2079
2114
}
2080
2115
}
2116
+
2117
+ mCustomConfigByHostCache .insert ( hostport, config );
2081
2118
return config;
2082
2119
}
2083
2120
@@ -2155,6 +2192,9 @@ bool QgsAuthManager::removeSslCertCustomConfig( const QString &id, const QString
2155
2192
return false ;
2156
2193
}
2157
2194
2195
+ mHasCheckedIfCustomConfigByHostExists = false ;
2196
+ mCustomConfigByHostCache .clear ();
2197
+
2158
2198
QSqlQuery query ( authDatabaseConnection () );
2159
2199
2160
2200
query.prepare ( QStringLiteral ( " DELETE FROM %1 WHERE id = :id AND host = :host" ).arg ( authDatabaseServersTable () ) );
0 commit comments