@@ -303,6 +303,9 @@ struct QueueThumbnailInfo {
303
303
304
304
/// The thumbnail's mime type.
305
305
content_type: Mime,
306
+
307
+ /// The thumbnail's file size in bytes.
308
+ file_size: usize,
306
309
}
307
310
308
311
/// A specific room's send queue ran into an error, and it has disabled itself.
@@ -964,6 +967,10 @@ struct QueueStorage {
964
967
965
968
/// To which room is this storage related.
966
969
room_id: OwnedRoomId,
970
+
971
+ /// In-memory mapping of media transaction IDs to thumbnail sizes for the
972
+ /// purpose of progress reporting.
973
+ thumbnail_size_cache: Arc<Mutex<HashMap<OwnedTransactionId, Vec<Option<usize>>>>>,
967
974
}
968
975
969
976
impl QueueStorage {
@@ -975,7 +982,11 @@ impl QueueStorage {
975
982
976
983
/// Create a new queue for queuing requests to be sent later.
977
984
fn new(client: WeakClient, room: OwnedRoomId) -> Self {
978
- Self { room_id: room, store: StoreLock { client, being_sent: Default::default() } }
985
+ Self {
986
+ room_id: room,
987
+ store: StoreLock { client, being_sent: Default::default() },
988
+ thumbnail_size_cache: Arc::new(Mutex::new(HashMap::new())),
989
+ }
979
990
}
980
991
981
992
/// Push a new event to be sent in the queue, with a default priority of 0.
@@ -1132,6 +1143,8 @@ impl QueueStorage {
1132
1143
warn!(txn_id = %transaction_id, "request marked as sent was missing from storage");
1133
1144
}
1134
1145
1146
+ self.thumbnail_size_cache.lock().await.remove(transaction_id);
1147
+
1135
1148
Ok(())
1136
1149
}
1137
1150
@@ -1172,6 +1185,8 @@ impl QueueStorage {
1172
1185
.remove_send_queue_request(&self.room_id, transaction_id)
1173
1186
.await?;
1174
1187
1188
+ self.thumbnail_size_cache.lock().await.remove(transaction_id);
1189
+
1175
1190
Ok(removed)
1176
1191
}
1177
1192
@@ -1234,6 +1249,8 @@ impl QueueStorage {
1234
1249
let client = guard.client()?;
1235
1250
let store = client.state_store();
1236
1251
1252
+ let media_sizes = vec![thumbnail.as_ref().map(|t| t.file_size)];
1253
+
1237
1254
let thumbnail_info = self
1238
1255
.push_thumbnail_and_media_uploads(
1239
1256
store,
@@ -1251,7 +1268,7 @@ impl QueueStorage {
1251
1268
.save_dependent_queued_request(
1252
1269
&self.room_id,
1253
1270
&upload_file_txn,
1254
- send_event_txn.into(),
1271
+ send_event_txn.clone(). into(),
1255
1272
created_at,
1256
1273
DependentQueuedRequestKind::FinishUpload {
1257
1274
local_echo: Box::new(event),
@@ -1261,6 +1278,8 @@ impl QueueStorage {
1261
1278
)
1262
1279
.await?;
1263
1280
1281
+ self.thumbnail_size_cache.lock().await.insert(send_event_txn, media_sizes);
1282
+
1264
1283
Ok(())
1265
1284
}
1266
1285
@@ -1281,6 +1300,7 @@ impl QueueStorage {
1281
1300
let store = client.state_store();
1282
1301
1283
1302
let mut finish_item_infos = Vec::with_capacity(item_queue_infos.len());
1303
+ let mut media_sizes = Vec::with_capacity(item_queue_infos.len());
1284
1304
1285
1305
let Some((first, rest)) = item_queue_infos.split_first() else {
1286
1306
return Ok(());
@@ -1303,6 +1323,7 @@ impl QueueStorage {
1303
1323
1304
1324
finish_item_infos
1305
1325
.push(FinishGalleryItemInfo { file_upload: upload_file_txn.clone(), thumbnail_info });
1326
+ media_sizes.push(thumbnail.as_ref().map(|t| t.file_size));
1306
1327
1307
1328
let mut last_upload_file_txn = upload_file_txn.clone();
1308
1329
@@ -1367,6 +1388,7 @@ impl QueueStorage {
1367
1388
file_upload: upload_file_txn.clone(),
1368
1389
thumbnail_info: thumbnail_info.cloned(),
1369
1390
});
1391
+ media_sizes.push(thumbnail.as_ref().map(|t| t.file_size));
1370
1392
1371
1393
last_upload_file_txn = upload_file_txn.clone();
1372
1394
}
@@ -1377,7 +1399,7 @@ impl QueueStorage {
1377
1399
.save_dependent_queued_request(
1378
1400
&self.room_id,
1379
1401
&last_upload_file_txn,
1380
- send_event_txn.into(),
1402
+ send_event_txn.clone(). into(),
1381
1403
created_at,
1382
1404
DependentQueuedRequestKind::FinishGallery {
1383
1405
local_echo: Box::new(event),
@@ -1386,6 +1408,8 @@ impl QueueStorage {
1386
1408
)
1387
1409
.await?;
1388
1410
1411
+ self.thumbnail_size_cache.lock().await.insert(send_event_txn, media_sizes);
1412
+
1389
1413
Ok(())
1390
1414
}
1391
1415
0 commit comments