Fetch the current document as a field map (for OLD row bindings). Issues a PointGet to the Data Plane and deserializes the response. Returns an empty map if the document doesn't exist or can't be read.
(
state: &SharedState,
tenant_id: TenantId,
collection: &str,
document_id: &str,
)
| 267 | /// Issues a PointGet to the Data Plane and deserializes the response. |
| 268 | /// Returns an empty map if the document doesn't exist or can't be read. |
| 269 | pub async fn fetch_old_row( |
| 270 | state: &SharedState, |
| 271 | tenant_id: TenantId, |
| 272 | collection: &str, |
| 273 | document_id: &str, |
| 274 | ) -> HashMap<String, nodedb_types::Value> { |
| 275 | let pk_bytes = document_id.as_bytes().to_vec(); |
| 276 | let surrogate = state |
| 277 | .surrogate_assigner |
| 278 | .lookup(collection, &pk_bytes) |
| 279 | .ok() |
| 280 | .flatten() |
| 281 | .unwrap_or(nodedb_types::Surrogate::ZERO); |
| 282 | let plan = crate::bridge::envelope::PhysicalPlan::Document(DocumentOp::PointGet { |
| 283 | collection: collection.to_string(), |
| 284 | document_id: document_id.to_string(), |
| 285 | surrogate, |
| 286 | pk_bytes, |
| 287 | rls_filters: Vec::new(), |
| 288 | system_as_of_ms: None, |
| 289 | valid_at_ms: None, |
| 290 | }); |
| 291 | let vshard_id = crate::types::VShardId::from_key(document_id.as_bytes()); |
| 292 | |
| 293 | let resp = match crate::control::server::dispatch_utils::dispatch_to_data_plane( |
| 294 | state, |
| 295 | tenant_id, |
| 296 | vshard_id, |
| 297 | plan, |
| 298 | TraceId::ZERO, |
| 299 | ) |
| 300 | .await |
| 301 | { |
| 302 | Ok(r) => r, |
| 303 | Err(_) => return HashMap::new(), |
| 304 | }; |
| 305 | |
| 306 | if resp.payload.is_empty() { |
| 307 | return HashMap::new(); |
| 308 | } |
| 309 | |
| 310 | // Decode the response payload (MessagePack or JSON). |
| 311 | let bytes = resp.payload.as_ref(); |
| 312 | if let Ok(serde_json::Value::Object(map)) = nodedb_types::json_from_msgpack(bytes) { |
| 313 | return map |
| 314 | .into_iter() |
| 315 | .map(|(k, v)| (k, nodedb_types::Value::from(v))) |
| 316 | .collect(); |
| 317 | } |
| 318 | if let Ok(serde_json::Value::Object(map)) = sonic_rs::from_slice::<serde_json::Value>(bytes) { |
| 319 | return map |
| 320 | .into_iter() |
| 321 | .map(|(k, v)| (k, nodedb_types::Value::from(v))) |
| 322 | .collect(); |
| 323 | } |
| 324 | |
| 325 | HashMap::new() |
| 326 | } |
no test coverage detected