@@ -160,60 +160,66 @@ impl RoomSendQueue {
160160 Span :: current ( ) . record ( "event_txn" , tracing:: field:: display ( & * send_event_txn) ) ;
161161 debug ! ( filename, %content_type, %upload_file_txn, "sending an attachment" ) ;
162162
163- // Cache the file itself in the cache store.
164163 let file_media_request = make_local_file_media_request ( & upload_file_txn) ;
165- room. client ( )
166- . event_cache_store ( )
167- . add_media_content ( & file_media_request, data. clone ( ) )
168- . await
169- . map_err ( |err| RoomSendQueueError :: StorageError ( err. into ( ) ) ) ?;
170164
171- // Process the thumbnail, if it's been provided.
172- let ( upload_thumbnail_txn, event_thumbnail_info, queue_thumbnail_info) = if let Some (
173- thumbnail,
174- ) =
175- config. thumbnail . take ( )
176- {
177- // Normalize information to retrieve the thumbnail in the cache store.
178- let info = thumbnail. info . as_ref ( ) ;
179- let height = info. and_then ( |info| info. height ) . unwrap_or_else ( || {
180- trace ! ( "thumbnail height is unknown, using 0 for the cache entry" ) ;
181- uint ! ( 0 )
182- } ) ;
183- let width = info. and_then ( |info| info. width ) . unwrap_or_else ( || {
184- trace ! ( "thumbnail width is unknown, using 0 for the cache entry" ) ;
185- uint ! ( 0 )
186- } ) ;
187-
188- let txn = TransactionId :: new ( ) ;
189- trace ! ( upload_thumbnail_txn = %txn, thumbnail_size = ?( height, width) , "attachment has a thumbnail" ) ;
190-
191- // Cache thumbnail in the cache store.
192- let thumbnail_media_request = make_local_thumbnail_media_request ( & txn, height, width) ;
193- room. client ( )
165+ let ( upload_thumbnail_txn, event_thumbnail_info, queue_thumbnail_info) = {
166+ let client = room. client ( ) ;
167+ let cache_store = client
194168 . event_cache_store ( )
195- . add_media_content ( & thumbnail_media_request , thumbnail . data . clone ( ) )
169+ . lock ( )
196170 . await
197- . map_err ( |err| RoomSendQueueError :: StorageError ( err. into ( ) ) ) ?;
198-
199- // Create the information required for filling the thumbnail section of the
200- // media event.
201- let thumbnail_info =
202- Box :: new ( assign ! ( thumbnail. info. map( ThumbnailInfo :: from) . unwrap_or_default( ) , {
203- mimetype: Some ( thumbnail. content_type. as_ref( ) . to_owned( ) )
204- } ) ) ;
205-
206- (
207- Some ( txn. clone ( ) ) ,
208- Some ( ( thumbnail_media_request. source . clone ( ) , thumbnail_info) ) ,
209- Some ( (
210- FinishUploadThumbnailInfo { txn, width, height } ,
211- thumbnail_media_request,
212- thumbnail. content_type ,
213- ) ) ,
214- )
215- } else {
216- Default :: default ( )
171+ . map_err ( RoomSendQueueStorageError :: LockError ) ?;
172+
173+ // Cache the file itself in the cache store.
174+ cache_store
175+ . add_media_content ( & file_media_request, data. clone ( ) )
176+ . await
177+ . map_err ( RoomSendQueueStorageError :: EventCacheStoreError ) ?;
178+
179+ // Process the thumbnail, if it's been provided.
180+ if let Some ( thumbnail) = config. thumbnail . take ( ) {
181+ // Normalize information to retrieve the thumbnail in the cache store.
182+ let info = thumbnail. info . as_ref ( ) ;
183+ let height = info. and_then ( |info| info. height ) . unwrap_or_else ( || {
184+ trace ! ( "thumbnail height is unknown, using 0 for the cache entry" ) ;
185+ uint ! ( 0 )
186+ } ) ;
187+ let width = info. and_then ( |info| info. width ) . unwrap_or_else ( || {
188+ trace ! ( "thumbnail width is unknown, using 0 for the cache entry" ) ;
189+ uint ! ( 0 )
190+ } ) ;
191+
192+ let txn = TransactionId :: new ( ) ;
193+ trace ! ( upload_thumbnail_txn = %txn, thumbnail_size = ?( height, width) , "attachment has a thumbnail" ) ;
194+
195+ // Cache thumbnail in the cache store.
196+ let thumbnail_media_request =
197+ make_local_thumbnail_media_request ( & txn, height, width) ;
198+ cache_store
199+ . add_media_content ( & thumbnail_media_request, thumbnail. data . clone ( ) )
200+ . await
201+ . map_err ( RoomSendQueueStorageError :: EventCacheStoreError ) ?;
202+
203+ // Create the information required for filling the thumbnail section of the
204+ // media event.
205+ let thumbnail_info = Box :: new (
206+ assign ! ( thumbnail. info. map( ThumbnailInfo :: from) . unwrap_or_default( ) , {
207+ mimetype: Some ( thumbnail. content_type. as_ref( ) . to_owned( ) )
208+ } ) ,
209+ ) ;
210+
211+ (
212+ Some ( txn. clone ( ) ) ,
213+ Some ( ( thumbnail_media_request. source . clone ( ) , thumbnail_info) ) ,
214+ Some ( (
215+ FinishUploadThumbnailInfo { txn, width, height } ,
216+ thumbnail_media_request,
217+ thumbnail. content_type ,
218+ ) ) ,
219+ )
220+ } else {
221+ Default :: default ( )
222+ }
217223 } ;
218224
219225 // Create the content for the media event.
@@ -296,8 +302,13 @@ impl QueueStorage {
296302
297303 trace ! ( from = ?from_req. source, to = ?sent_media. file, "renaming media file key in cache store" ) ;
298304
299- client
305+ let cache_store = client
300306 . event_cache_store ( )
307+ . lock ( )
308+ . await
309+ . map_err ( RoomSendQueueStorageError :: LockError ) ?;
310+
311+ cache_store
301312 . replace_media_key (
302313 & from_req,
303314 & MediaRequestParameters {
@@ -320,8 +331,7 @@ impl QueueStorage {
320331 // Reuse the same format for the cached thumbnail with the final MXC ID.
321332 let new_format = from_req. format . clone ( ) ;
322333
323- client
324- . event_cache_store ( )
334+ cache_store
325335 . replace_media_key (
326336 & from_req,
327337 & MediaRequestParameters { source : new_source, format : new_format } ,
0 commit comments