@@ -472,6 +472,14 @@ impl Context {
472472 // Allow at least 1 message every second + a burst of 3.
473473 * lock = Ratelimit :: new ( Duration :: new ( 3 , 0 ) , 3.0 ) ;
474474 }
475+
476+ // The next line is mainly for iOS:
477+ // iOS starts a separate process for receiving notifications and if the user concurrently
478+ // starts the app, the UI process opens the database but waits with calling start_io()
479+ // until the notifications process finishes.
480+ // Now, some configs may have changed, so, we need to invalidate the cache.
481+ self . sql . config_cache . write ( ) . await . clear ( ) ;
482+
475483 self . scheduler . start ( self . clone ( ) ) . await ;
476484 }
477485
@@ -2064,4 +2072,41 @@ mod tests {
20642072
20652073 Ok ( ( ) )
20662074 }
2075+
2076+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
2077+ async fn test_cache_is_cleared_when_io_is_started ( ) -> Result < ( ) > {
2078+ let alice = TestContext :: new_alice ( ) . await ;
2079+ assert_eq ! (
2080+ alice. get_config( Config :: ShowEmails ) . await ?,
2081+ Some ( "2" . to_string( ) )
2082+ ) ;
2083+
2084+ // Change the config circumventing the cache
2085+ // This simulates what the notfication plugin on iOS might do
2086+ // because it runs in a different process
2087+ alice
2088+ . sql
2089+ . execute (
2090+ "INSERT OR REPLACE INTO config (keyname, value) VALUES ('show_emails', '0')" ,
2091+ ( ) ,
2092+ )
2093+ . await ?;
2094+
2095+ // Alice's Delta Chat doesn't know about it yet:
2096+ assert_eq ! (
2097+ alice. get_config( Config :: ShowEmails ) . await ?,
2098+ Some ( "2" . to_string( ) )
2099+ ) ;
2100+
2101+ // Starting IO will fail of course because no server settings are configured,
2102+ // but it should invalidate the caches:
2103+ alice. start_io ( ) . await ;
2104+
2105+ assert_eq ! (
2106+ alice. get_config( Config :: ShowEmails ) . await ?,
2107+ Some ( "0" . to_string( ) )
2108+ ) ;
2109+
2110+ Ok ( ( ) )
2111+ }
20672112}
0 commit comments