@@ -472,6 +472,14 @@ impl Context {
472
472
// Allow at least 1 message every second + a burst of 3.
473
473
* lock = Ratelimit :: new ( Duration :: new ( 3 , 0 ) , 3.0 ) ;
474
474
}
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
+
475
483
self . scheduler . start ( self . clone ( ) ) . await ;
476
484
}
477
485
@@ -2064,4 +2072,41 @@ mod tests {
2064
2072
2065
2073
Ok ( ( ) )
2066
2074
}
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
+ }
2067
2112
}
0 commit comments