@@ -36,6 +36,12 @@ pub trait ConfigInterface {
36
36
config_update : storage:: ConfigUpdate ,
37
37
) -> CustomResult < storage:: Config , errors:: StorageError > ;
38
38
39
+ async fn update_config_in_database (
40
+ & self ,
41
+ key : & str ,
42
+ config_update : storage:: ConfigUpdate ,
43
+ ) -> CustomResult < storage:: Config , errors:: StorageError > ;
44
+
39
45
async fn delete_config_by_key ( & self , key : & str ) -> CustomResult < bool , errors:: StorageError > ;
40
46
}
41
47
@@ -49,14 +55,26 @@ impl ConfigInterface for Store {
49
55
config. insert ( & conn) . await . map_err ( Into :: into) . into_report ( )
50
56
}
51
57
58
+ async fn update_config_in_database (
59
+ & self ,
60
+ key : & str ,
61
+ config_update : storage:: ConfigUpdate ,
62
+ ) -> CustomResult < storage:: Config , errors:: StorageError > {
63
+ let conn = connection:: pg_connection_write ( self ) . await ?;
64
+ storage:: Config :: update_by_key ( & conn, key, config_update)
65
+ . await
66
+ . map_err ( Into :: into)
67
+ . into_report ( )
68
+ }
69
+
52
70
//update in DB and remove in redis and cache
53
71
async fn update_config_by_key (
54
72
& self ,
55
73
key : & str ,
56
74
config_update : storage:: ConfigUpdate ,
57
75
) -> CustomResult < storage:: Config , errors:: StorageError > {
58
76
cache:: publish_and_redact ( self , CacheKind :: Config ( key. into ( ) ) , || {
59
- self . update_config_by_key ( key, config_update)
77
+ self . update_config_in_database ( key, config_update)
60
78
} )
61
79
. await
62
80
}
@@ -124,6 +142,14 @@ impl ConfigInterface for MockDb {
124
142
Ok ( config_new)
125
143
}
126
144
145
+ async fn update_config_in_database (
146
+ & self ,
147
+ key : & str ,
148
+ config_update : storage:: ConfigUpdate ,
149
+ ) -> CustomResult < storage:: Config , errors:: StorageError > {
150
+ self . update_config_by_key ( key, config_update) . await
151
+ }
152
+
127
153
async fn update_config_by_key (
128
154
& self ,
129
155
key : & str ,
@@ -166,7 +192,7 @@ impl ConfigInterface for MockDb {
166
192
result
167
193
}
168
194
169
- async fn find_config_by_key_from_db (
195
+ async fn find_config_by_key (
170
196
& self ,
171
197
key : & str ,
172
198
) -> CustomResult < storage:: Config , errors:: StorageError > {
@@ -178,15 +204,10 @@ impl ConfigInterface for MockDb {
178
204
} )
179
205
}
180
206
181
- async fn find_config_by_key (
207
+ async fn find_config_by_key_from_db (
182
208
& self ,
183
209
key : & str ,
184
210
) -> CustomResult < storage:: Config , errors:: StorageError > {
185
- let configs = self . configs . lock ( ) . await ;
186
- let config = configs. iter ( ) . find ( |c| c. key == key) . cloned ( ) ;
187
-
188
- config. ok_or_else ( || {
189
- errors:: StorageError :: ValueNotFound ( "cannot find config" . to_string ( ) ) . into ( )
190
- } )
211
+ self . find_config_by_key ( key) . await
191
212
}
192
213
}
0 commit comments