Retrieve objects from the database. The `object_handle` classifies the request identifier: an [`ObjectHandle::Tags`] expands to every object carrying all of the requested tags, while any other variant resolves to the single UID it wraps. Returns a `DbResult` containing a `HashMap` where the keys are the `uid`s and the values are the `ObjectWithMetadata`. # Arguments `object_handle` - the class
(
&self,
object_handle: ObjectHandle<'_>,
)
| 238 | /// |
| 239 | /// * `DbResult<HashMap<String, Arc<ObjectWithMetadata>>>` - A result containing a map of `uid`s to shared `ObjectWithMetadata`. |
| 240 | pub async fn retrieve_objects( |
| 241 | &self, |
| 242 | object_handle: ObjectHandle<'_>, |
| 243 | ) -> DbResult<HashMap<String, Arc<ObjectWithMetadata>>> { |
| 244 | Box::pin(self.record("retrieve_objects", async move { |
| 245 | if let ObjectHandle::Tags(json) = object_handle { |
| 246 | let tags: HashSet<String> = serde_json::from_str(json)?; |
| 247 | let uids = self.list_uids_for_tags(&tags).await?; |
| 248 | let mut results = HashMap::with_capacity(uids.len()); |
| 249 | for uid in uids { |
| 250 | if let Some(owm) = self.retrieve_object_arc(&uid).await? { |
| 251 | results.insert(uid, owm); |
| 252 | } |
| 253 | } |
| 254 | return Ok(results); |
| 255 | } |
| 256 | let uid = object_handle.as_str(); |
| 257 | let mut results = HashMap::with_capacity(1); |
| 258 | if let Some(owm) = self.retrieve_object_arc(uid).await? { |
| 259 | results.insert(uid.to_owned(), owm); |
| 260 | } |
| 261 | Ok(results) |
| 262 | })) |
| 263 | .await |
| 264 | } |
| 265 | |
| 266 | /// Retrieve state and attributes of an object for cache validation. |
| 267 | pub async fn retrieve_state(&self, uid: &str) -> DbResult<Option<(State, Attributes)>> { |