Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3403163
D10247.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.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
@@ -423,6 +423,58 @@
.map_err(Error::from)
}
+ /// Gets user's device list history
+ pub async fn get_device_list_history(
+ &self,
+ user_id: impl Into<String>,
+ since: Option<DateTime<Utc>>,
+ ) -> Result<Vec<DeviceListRow>, Error> {
+ let rows = if let Some(since) = since {
+ // When timestamp is provided, it's better to query device lists by timestamp LSI
+ self
+ .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(self, 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)
+ }
+
/// Checks if given device exists on user's current device list
pub async fn device_exists(
&self,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 4, 1:41 AM (6 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2610124
Default Alt Text
D10247.diff (2 KB)
Attached To
Mode
D10247: [identity] Add function to get device list history
Attached
Detach File
Event Timeline
Log In to Comment