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)
| 552 | /// A `ViewInfo` struct with the view's metadata, or an error if the view |
| 553 | /// doesn't exist. |
| 554 | pub fn get_view_info(&self, name: &str) -> Result<ViewInfo, RepositoryError> { |
| 555 | let txn = self |
| 556 | .pristine |
| 557 | .read_txn() |
| 558 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 559 | |
| 560 | let view = txn |
| 561 | .get_view(name) |
| 562 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 563 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 564 | name: name.to_string(), |
| 565 | })?; |
| 566 | |
| 567 | // Resolve parent name and compute own/inherited change counts by |
| 568 | // actual graph membership rather than by assuming the own log is a |
| 569 | // superset of the parent (which only holds for `create_view_from` |
| 570 | // drafts, not for record- or split-created drafts). |
| 571 | let (parent_name, own_change_count, inherited_change_count) = match view.parent { |
| 572 | Some(parent_id) => { |
| 573 | match txn |
| 574 | .get_view_by_id(parent_id) |
| 575 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 576 | { |
| 577 | Some(parent) => { |
| 578 | let parent_visible = collect_visible_change_ids(&txn, &parent)?; |
| 579 | let own_ids = collect_view_change_ids(&txn, &view)?; |
| 580 | let own = own_ids.difference(&parent_visible).count() as u64; |
| 581 | (Some(parent.name), own, parent_visible.len() as u64) |
| 582 | } |
| 583 | None => (None, view.change_count, 0), |
| 584 | } |
| 585 | } |
| 586 | None => (None, view.change_count, 0), |
| 587 | }; |
| 588 | |
| 589 | Ok(ViewInfo { |
| 590 | name: view.name.clone(), |
| 591 | state: view.state, |
| 592 | change_count: view.change_count, |
| 593 | own_change_count, |
| 594 | inherited_change_count, |
| 595 | scope: view.kind, |
| 596 | parent_name, |
| 597 | }) |
| 598 | } |
| 599 | |
| 600 | /// Create a new Draft view parented on an explicit named parent. |
| 601 | /// |