Get information about a view. Returns the view's metadata including its Merkle state and change count. # Arguments `name` - The name of the view to query # Returns A `ViewInfo` struct with the view's metadata, or an error if the view doesn't exist.
(&self, name: &str)
| 501 | /// A `ViewInfo` struct with the view's metadata, or an error if the view |
| 502 | /// doesn't exist. |
| 503 | pub fn get_view_info(&self, name: &str) -> Result<ViewInfo, RepositoryError> { |
| 504 | let txn = self |
| 505 | .pristine |
| 506 | .read_txn() |
| 507 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 508 | |
| 509 | let view = txn |
| 510 | .get_view(name) |
| 511 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 512 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 513 | name: name.to_string(), |
| 514 | })?; |
| 515 | |
| 516 | // Resolve parent name and compute own change count. |
| 517 | let (parent_name, parent_change_count) = if let Some(parent_id) = view.parent { |
| 518 | match txn |
| 519 | .get_view_by_id(parent_id) |
| 520 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 521 | { |
| 522 | Some(p) => (Some(p.name), p.change_count), |
| 523 | None => (None, 0), |
| 524 | } |
| 525 | } else { |
| 526 | (None, 0) |
| 527 | }; |
| 528 | |
| 529 | let own_change_count = if view.parent.is_some() { |
| 530 | view.change_count.saturating_sub(parent_change_count) |
| 531 | } else { |
| 532 | view.change_count |
| 533 | }; |
| 534 | |
| 535 | Ok(ViewInfo { |
| 536 | name: view.name.clone(), |
| 537 | state: view.state, |
| 538 | change_count: view.change_count, |
| 539 | own_change_count, |
| 540 | scope: view.kind, |
| 541 | parent_name, |
| 542 | }) |
| 543 | } |
| 544 | } |