Improve local filetree view state and sidebar performance

This commit is contained in:
lix-2026
2026-05-27 11:31:12 +08:00
parent 58e2fdb5d8
commit 3ae33cc21d
56 changed files with 8614 additions and 461 deletions
+51 -2
View File
@@ -139,7 +139,12 @@ pub async fn update_options(
)
.with_context(context)
})?;
let (wired_options, ignored_options, warnings) = filter_wired_page_options(options);
let (wired_options, ignored_options, warnings) =
if input.effective_source_kind().as_deref() == Some("local_folder") {
filter_local_ui_preference_options(options)
} else {
filter_wired_page_options(options)
};
page_command(
state,
context,
@@ -235,7 +240,16 @@ async fn page_command(
)
.with_context(context)
})?;
crate::routes::update_local_page_options(&root_uri, &document_id, &options)?
crate::routes::ui_preferences::update_page_preferences_from_value(
state,
context,
context.auth.actor_id.trim(),
workspace_id.as_deref().unwrap_or_default(),
"local_folder",
&root_uri,
&document_id,
&options,
)?
}
_ => {
return Err(WebError::bad_request_code(
@@ -443,6 +457,41 @@ fn filter_wired_page_options(options: Value) -> (Value, Vec<String>, Vec<Value>)
(Value::Object(out), ignored, warnings)
}
fn filter_local_ui_preference_options(options: Value) -> (Value, Vec<String>, Vec<Value>) {
let allowed = [
"wideLayout",
"smallText",
"layoutDensity",
"pageFont",
"showHeadingNumbers",
"showToc",
"showStructure",
"showWordCount",
"collapseBacklinks",
"hideChildPages",
"showBlockRefCount",
"hideTitleHeader",
];
let mut out = serde_json::Map::new();
let mut ignored = Vec::new();
let mut warnings = Vec::new();
if let Value::Object(map) = options {
for (key, value) in map {
if allowed.contains(&key.as_str()) {
out.insert(key, value);
} else {
warnings.push(json!({
"code": "page_option_not_wired",
"field": key.clone(),
"message": "页面设置字段尚未接入 SQLite UI 偏好,已忽略"
}));
ignored.push(key);
}
}
}
(Value::Object(out), ignored, warnings)
}
fn summarize_blocks(content: &Value) -> Vec<Value> {
let mut out = Vec::new();
collect_blocks(content, &mut out);