Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32626522
D10798.1767474835.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D10798.1767474835.diff
View Options
diff --git a/services/identity/src/database/device_list.rs b/services/identity/src/database/device_list.rs
--- a/services/identity/src/database/device_list.rs
+++ b/services/identity/src/database/device_list.rs
@@ -692,9 +692,10 @@
let put_device_operation =
TransactWriteItem::builder().put(put_device).build();
- Ok(put_device_operation)
+ Ok(Some(put_device_operation))
})
- .await
+ .await?;
+ Ok(())
}
/// Removes device from user's device list. If the device doesn't exist, the
@@ -741,8 +742,10 @@
let operation =
TransactWriteItem::builder().delete(delete_device).build();
- Ok(operation)
+ Ok(Some(operation))
})
+ .await?;
+ Ok(())
.await
}
@@ -750,6 +753,7 @@
/// generates a new device list and updates the timestamp in the users table.
/// This is done in a transaction. Operation fails if the device list has been
/// updated concurrently (timestamp mismatch).
+ /// Returns the new device list row that has been saved to database.
async fn transact_update_devicelist(
&self,
user_id: &str,
@@ -762,8 +766,8 @@
action: impl FnOnce(
&mut Vec<String>,
Vec<DeviceRow>,
- ) -> Result<TransactWriteItem, Error>,
- ) -> Result<(), Error> {
+ ) -> Result<Option<TransactWriteItem>, Error>,
+ ) -> Result<DeviceListRow, Error> {
let previous_timestamp =
get_current_devicelist_timestamp(self, user_id).await?;
let current_devices_data = self.get_current_devices(user_id).await?;
@@ -787,7 +791,7 @@
// Put updated device list (a new version)
let put_device_list = Put::builder()
.table_name(devices_table::NAME)
- .set_item(Some(new_device_list.into()))
+ .set_item(Some(new_device_list.clone().into()))
.condition_expression(
"attribute_not_exists(#user_id) AND attribute_not_exists(#item_id)",
)
@@ -797,12 +801,20 @@
let put_device_list_operation =
TransactWriteItem::builder().put(put_device_list).build();
+ let operations = if let Some(operation) = operation {
+ vec![
+ operation,
+ put_device_list_operation,
+ timestamp_update_operation,
+ ]
+ } else {
+ vec![put_device_list_operation, timestamp_update_operation]
+ };
+
self
.client
.transact_write_items()
- .transact_items(operation)
- .transact_items(put_device_list_operation)
- .transact_items(timestamp_update_operation)
+ .set_transact_items(Some(operations))
.send()
.await
.map_err(|e| match DynamoDBError::from(e) {
@@ -823,7 +835,7 @@
}
})?;
- Ok(())
+ Ok(new_device_list)
}
/// Deletes all user data from devices table
@@ -1048,8 +1060,9 @@
let device_list_set = list.iter().collect::<HashSet<_>>();
- if let Some(corrupt_device_id) =
- device_list_set.difference(&actual_device_ids).next()
+ if let Some(corrupt_device_id) = device_list_set
+ .symmetric_difference(&actual_device_ids)
+ .next()
{
error!(
"Device list is corrupt (unknown deviceID={})",
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 3, 9:13 PM (12 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5890825
Default Alt Text
D10798.1767474835.diff (3 KB)
Attached To
Mode
D10798: [identity] Make device list transactions more flexible
Attached
Detach File
Event Timeline
Log In to Comment