Fix starred scope page tree and local edit save
This commit is contained in:
@@ -2767,6 +2767,20 @@ fn load_local_folder_file_tree_scope_snapshot(
|
||||
|
||||
pub fn load_local_folder_page_tree_snapshot(
|
||||
root_uri: &str,
|
||||
) -> Result<ProjectionSnapshot, WebError> {
|
||||
load_local_folder_page_tree_snapshot_for_scope(root_uri, None)
|
||||
}
|
||||
|
||||
pub fn load_local_folder_page_tree_scope_snapshot(
|
||||
root_uri: &str,
|
||||
parent_relative_path: &str,
|
||||
) -> Result<ProjectionSnapshot, WebError> {
|
||||
load_local_folder_page_tree_snapshot_for_scope(root_uri, Some(parent_relative_path))
|
||||
}
|
||||
|
||||
fn load_local_folder_page_tree_snapshot_for_scope(
|
||||
root_uri: &str,
|
||||
parent_relative_path: Option<&str>,
|
||||
) -> Result<ProjectionSnapshot, WebError> {
|
||||
#[cfg(test)]
|
||||
LOCAL_PAGE_TREE_SNAPSHOT_TEST_LOADS.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
@@ -2787,9 +2801,25 @@ pub fn load_local_folder_page_tree_snapshot(
|
||||
|
||||
let workspace_id = local_workspace_id(&canonical_root);
|
||||
let root_source_uri = file_uri_for_path(&canonical_root);
|
||||
let parent_relative_path = parent_relative_path
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty() && *value != ".")
|
||||
.unwrap_or("");
|
||||
let scan_root = if parent_relative_path.is_empty() {
|
||||
canonical_root.clone()
|
||||
} else {
|
||||
resolve_metadata_relative_path(&canonical_root, parent_relative_path)?
|
||||
};
|
||||
if !scan_root.is_dir() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"local_folder_parent_not_directory",
|
||||
"PageTree scope parentRelativePath 必须指向目录",
|
||||
));
|
||||
}
|
||||
let watch_revision = local_folder_watch_revision_for_root(&canonical_root, &root_source_uri)?;
|
||||
let cache_key = format!("{root_source_uri}\n{parent_relative_path}");
|
||||
if let Ok(cache) = local_page_tree_snapshot_cache().lock() {
|
||||
if let Some(entry) = cache.get(&root_source_uri) {
|
||||
if let Some(entry) = cache.get(&cache_key) {
|
||||
if entry.watch_revision.revision == watch_revision.revision
|
||||
&& entry.watch_revision.entry_count == watch_revision.entry_count
|
||||
&& entry.watch_revision.latest_modified_ms == watch_revision.latest_modified_ms
|
||||
@@ -2804,7 +2834,7 @@ pub fn load_local_folder_page_tree_snapshot(
|
||||
LOCAL_PAGE_TREE_SNAPSHOT_SCAN_TEST_LOADS.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
scan_markdown_page_tree(
|
||||
&canonical_root,
|
||||
&canonical_root,
|
||||
&scan_root,
|
||||
None,
|
||||
0,
|
||||
None,
|
||||
@@ -2859,6 +2889,7 @@ pub fn load_local_folder_page_tree_snapshot(
|
||||
"projection": "page_tree",
|
||||
"sourceKind": "local_folder",
|
||||
"rootUri": root_source_uri,
|
||||
"parentRelativePath": parent_relative_path,
|
||||
"watchRevision": watch_revision,
|
||||
"items": items,
|
||||
}),
|
||||
@@ -2868,7 +2899,7 @@ pub fn load_local_folder_page_tree_snapshot(
|
||||
cache.clear();
|
||||
}
|
||||
cache.insert(
|
||||
root_source_uri,
|
||||
cache_key,
|
||||
LocalPageTreeSnapshotCacheEntry {
|
||||
watch_revision,
|
||||
snapshot: snapshot.clone(),
|
||||
|
||||
Reference in New Issue
Block a user