Avoid deserializing all themes to compute settings JSON schema
This commit is contained in:
parent
0f5489397f
commit
c69d0d50cd
2 changed files with 19 additions and 7 deletions
|
@ -5,6 +5,7 @@ use parking_lot::Mutex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::{
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicUsize, Ordering::SeqCst},
|
atomic::{AtomicUsize, Ordering::SeqCst},
|
||||||
|
@ -43,7 +44,7 @@ impl ThemeRegistry {
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list(&self, staff: bool) -> impl Iterator<Item = ThemeMeta> + '_ {
|
pub fn list_names(&self, staff: bool) -> impl Iterator<Item = Cow<str>> + '_ {
|
||||||
let mut dirs = self.assets.list("themes/");
|
let mut dirs = self.assets.list("themes/");
|
||||||
|
|
||||||
if !staff {
|
if !staff {
|
||||||
|
@ -53,10 +54,21 @@ impl ThemeRegistry {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
dirs.into_iter().filter_map(|path| {
|
fn get_name(path: &str) -> Option<&str> {
|
||||||
let filename = path.strip_prefix("themes/")?;
|
path.strip_prefix("themes/")?.strip_suffix(".json")
|
||||||
let theme_name = filename.strip_suffix(".json")?;
|
}
|
||||||
self.get(theme_name).ok().map(|theme| theme.meta.clone())
|
|
||||||
|
dirs.into_iter().filter_map(|path| match path {
|
||||||
|
Cow::Borrowed(path) => Some(Cow::Borrowed(get_name(path)?)),
|
||||||
|
Cow::Owned(path) => Some(Cow::Owned(get_name(&path)?.to_string())),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list(&self, staff: bool) -> impl Iterator<Item = ThemeMeta> + '_ {
|
||||||
|
self.list_names(staff).filter_map(|theme_name| {
|
||||||
|
self.get(theme_name.as_ref())
|
||||||
|
.ok()
|
||||||
|
.map(|theme| theme.meta.clone())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,8 +178,8 @@ impl settings::Setting for ThemeSettings {
|
||||||
let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>();
|
let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>();
|
||||||
let theme_names = cx
|
let theme_names = cx
|
||||||
.global::<Arc<ThemeRegistry>>()
|
.global::<Arc<ThemeRegistry>>()
|
||||||
.list(params.staff_mode)
|
.list_names(params.staff_mode)
|
||||||
.map(|theme| Value::String(theme.name.clone()))
|
.map(|theme_name| Value::String(theme_name.to_string()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let theme_name_schema = SchemaObject {
|
let theme_name_schema = SchemaObject {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue