Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3399251
D10247.id34413.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10247.id34413.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
@@ -401,6 +401,57 @@
.map_err(Error::from)
}
+/// Gets user's device list history
+pub async fn get_device_list_history(
+ db: &crate::database::DatabaseClient,
+ user_id: impl Into<String>,
+ since: Option<DateTime<Utc>>,
+) -> Result<Vec<DeviceListRow>, Error> {
+ let rows = if let Some(since) = since {
+ // When tiemstamp is provided, it's better to query deice lists by timestamp LSI
+ db.client
+ .query()
+ .table_name(devices_table::NAME)
+ .index_name(devices_table::TIMESTAMP_INDEX_NAME)
+ .consistent_read(true)
+ .key_condition_expression("#user_id = :user_id AND #timestamp > :since")
+ .expression_attribute_names("#user_id", ATTR_USER_ID)
+ .expression_attribute_names("#timestamp", ATTR_TIMESTAMP)
+ .expression_attribute_values(
+ ":user_id",
+ AttributeValue::S(user_id.into()),
+ )
+ .expression_attribute_values(
+ ":since",
+ AttributeValue::N(since.timestamp_millis().to_string()),
+ )
+ .send()
+ .await
+ .map_err(|e| {
+ error!("Failed to query device list updates by index: {:?}", e);
+ Error::AwsSdk(e.into())
+ })?
+ .items
+ } else {
+ // Query all device lists for user
+ query_rows_with_prefix(db, user_id, DEVICE_LIST_KEY_PREFIX)
+ .send()
+ .await
+ .map_err(|e| {
+ error!("Failed to query device list updates (all): {:?}", e);
+ Error::AwsSdk(e.into())
+ })?
+ .items
+ };
+
+ rows
+ .unwrap_or_default()
+ .into_iter()
+ .map(DeviceListRow::try_from)
+ .collect::<Result<Vec<DeviceListRow>, DBItemError>>()
+ .map_err(Error::from)
+}
+
/// Adds new device to user's device list. If the device already exists, the
/// operation fails. Transactionally generates new device list version.
pub async fn add_device(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 2:38 AM (20 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2609836
Default Alt Text
D10247.id34413.diff (2 KB)
Attached To
Mode
D10247: [identity] Add function to get device list history
Attached
Detach File
Event Timeline
Log In to Comment