Skip to content

Commit

Permalink
Trying to get build time down to something reasonable
Browse files Browse the repository at this point in the history
New file config.toml - build with 12 threas

Also

restored compile.toml - now cargo make ci works

This started doing executing

```
cargo clippy --all-features --all-targets
```

which picked up mistakes in "ssr" builds.
  • Loading branch information
martinfrances107 committed Aug 9, 2024
1 parent 5474bff commit 454aca6
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 51 deletions.
11 changes: 11 additions & 0 deletions compile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tasks.build]
toolchain = "stable"
command = "cargo"
args = ["build-all-features"]
install_crate = "cargo-all-features"

[tasks.check]
toolchain = "stable"
command = "cargo"
args = ["check-all-features"]
install_crate = "cargo-all-features"
2 changes: 2 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["-Z", "threads=12"]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"autoprefixer": "^10.4.15",
"postcss": "^8.4.29",
"tailwindcss": "^3.3.3"
}
},
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a"
}
18 changes: 10 additions & 8 deletions src/component/file_lister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn is_not_hidden(entry: &walkdir::DirEntry) -> bool {
// IMAGE_PREFIX santitisation check.
// [url] must map to a valid directory.
//
#[allow(clippy::unused_async)]
#[server]
pub async fn add_list_url(url: String) -> Result<String, ServerFnError> {
use crate::pages::UrlSanitizationError;
Expand All @@ -37,8 +38,8 @@ pub async fn add_list_url(url: String) -> Result<String, ServerFnError> {
leptos::logging::log!("server: entry add_root_url");
match GLOBAL_STATE.lock() {
Ok(mut state) => {
match state.set_list_dir_from_url(url) {
Ok(_) => Ok(String::from("add_list_url")),
match state.set_list_dir_from_url(&url) {
Ok(()) => Ok(String::from("add_list_url")),
Err(UrlSanitizationError::MissingPrefix) => {
Err(ServerFnError::Args(format!(
"URL must be prefixed with {IMAGE_PREFIX}"
Expand All @@ -59,6 +60,7 @@ pub async fn add_list_url(url: String) -> Result<String, ServerFnError> {
}
}

#[allow(clippy::unused_async)]
#[server]
pub async fn get_list_url(
version: usize,
Expand All @@ -69,11 +71,11 @@ pub async fn get_list_url(
let version = version + 1;
match crate::pages::GLOBAL_STATE.lock() {
Ok(state) => {
let container_dir = state.container_dir().clone();
let container_dir = state.container_dir();
let uuid_url = WalkDir::new(state.list_dir())
.max_depth(1)
.into_iter()
.filter_entry(|e| is_not_hidden(e))
.filter_entry(is_not_hidden)
.filter_map(|entry| match entry {
Ok(entry) => {
if entry.path().is_dir() {
Expand All @@ -85,10 +87,10 @@ pub async fn get_list_url(
Err(_e) => None,
})
.filter_map(|entry| {
match entry.path().strip_prefix(container_dir.clone()) {
Ok(url) => Some(url.display().to_string()),
Err(_) => None,
}
entry
.path()
.strip_prefix(container_dir.clone())
.map_or(None, |url| Some(url.display().to_string()))
})
.enumerate()
.map(|(i, url)| (cantor_pair(i, version), url))
Expand Down
6 changes: 3 additions & 3 deletions src/component/file_lister/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub fn Lister() -> impl IntoView {

// Move vlaue into the inputvalue
match input_element.get() {
Some(input) => {
select_value_set.set(String::from(value));
Some(_) => {
select_value_set.set(value);
}
None => {
log::warn!(
Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn Lister() -> impl IntoView {
id="fl"
placeholder="select directory"
node_ref=input_element
value={select_value.clone()}
value={select_value}
type="text"
/>

Expand Down
19 changes: 8 additions & 11 deletions src/component/image_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::Serialize;

use crate::pages::search::SRElem;

#[allow(clippy::unused_async)]
#[server]
pub async fn add_meta_data(
url: Option<String>,
Expand All @@ -19,25 +20,21 @@ pub async fn add_meta_data(
log::debug!("server: entry metadata");

match GLOBAL_STATE.lock() {
Ok(mut state) => match url {
Some(url) => {
state.metadata = match state.index.md_store.get(&url) {
Some(metadata) => Some(metadata.clone()),
None => None,
};
Ok(state.metadata.clone())
}
None => {
Ok(mut state) => {
if let Some(url) = url {
state.metadata = state.index.md_store.get(&url).cloned();
} else {
state.metadata = None;
Ok(state.metadata.clone())
}
},
Ok(state.metadata.clone())
}
Err(e) => {
panic!("/search query - could not unlock {e}");
}
}
}

#[allow(clippy::unused_async)]
#[server]
pub async fn get_metadata() -> Result<Option<Vec<Field>>, ServerFnError> {
use crate::pages::GLOBAL_STATE;
Expand Down
17 changes: 8 additions & 9 deletions src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ impl Index {
.strip_prefix(&container_dir)
.expect("indexer new_with_extension: strip_prefix failed")
.display()
.to_string()
);

match std::fs::File::open(de.path()) {
Expand Down Expand Up @@ -163,7 +162,7 @@ impl Index {
}

/// Can I refactor?
/// Drop the ROOT_DIR
/// Drop the `ROOT_DIR`
/// Inject two simulated files.
/// then assert we can see only one returned by search.
#[cfg(test)]
Expand Down Expand Up @@ -208,12 +207,12 @@ mod test {
let result = index.model.search_query(&sq);

let expected = vec![
(PathBuf::from("/home/martin/build/exif-samples/jpg/Sony_HDR-HC3.jpg"), 0.026654188),
(PathBuf::from("/home/martin/build/exif-samples/jpg/hdr/canon_hdr_YES.jpg"), 0.015657004),
(PathBuf::from("/home/martin/build/exif-samples/jpg/hdr/canon_hdr_NO.jpg"), 0.015657004),
(PathBuf::from("/home/martin/build/exif-samples/jpg/hdr/iphone_hdr_YES.jpg"), 0.009995321),
(PathBuf::from("/home/martin/build/exif-samples/jpg/hdr/iphone_hdr_NO.jpg"), 0.009906866),
(PathBuf::from("/home/martin/build/exif-samples/jpg/mobile/HMD_Nokia_8.3_5G_hdr.jpg"), 0.0073168357)]
(PathBuf::from("/home/martin/build/exif-samples/jpg/Sony_HDR-HC3.jpg"), 0.026_654_188),
(PathBuf::from("/home/martin/build/exif-samples/jpg/hdr/canon_hdr_YES.jpg"), 0.015_657_004),
(PathBuf::from("/home/martin/build/exif-samples/jpg/hdr/canon_hdr_NO.jpg"), 0.015_657_004),
(PathBuf::from("/home/martin/build/exif-samples/jpg/hdr/iphone_hdr_YES.jpg"), 0.009_995_321),
(PathBuf::from("/home/martin/build/exif-samples/jpg/hdr/iphone_hdr_NO.jpg"), 0.009_906_866),
(PathBuf::from("/home/martin/build/exif-samples/jpg/mobile/HMD_Nokia_8.3_5G_hdr.jpg"), 0.007_316_835_7)]
;
assert_eq!(result, expected);
}
Expand All @@ -237,7 +236,7 @@ mod test {
PathBuf::from(
"/home/martin/build/exif-samples/jpg/long_description.jpg",
),
0.01150077_f32,
0.011_500_77_f32,
)];
assert_eq!(result, expected);
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ cfg_if! {
impl GlobalState {
// Reject urls without a prefix "/images"
// Reject invalid DIRECTORY names ( within the container directory ).
fn sanitize_url(&self, url: String) -> Result<PathBuf, UrlSanitizationError> {
fn sanitize_url(&self, url: &str) -> Result<PathBuf, UrlSanitizationError> {

let list_dir = match url.strip_prefix(IMAGE_PREFIX) {
Some(filename_suffix) => {
PathBuf::from(self.container_dir.join(filename_suffix))
self.container_dir.join(filename_suffix)
}
None => {
// Malformed input.
Expand Down Expand Up @@ -77,7 +77,7 @@ cfg_if! {
}
}

pub(crate) fn set_list_dir_from_url(&mut self, url: String) -> Result<(), UrlSanitizationError>{
pub(crate) fn set_list_dir_from_url(&mut self, url: &str) -> Result<(), UrlSanitizationError>{
match self.sanitize_url(url) {
Ok(dir) => {
self.list_dir = dir;
Expand Down
29 changes: 14 additions & 15 deletions src/pages/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct SearchResult {
pub version: usize,
}

#[allow(clippy::unused_async)]
#[server]
pub async fn add_query(query: String) -> Result<(), ServerFnError> {
use tracing::log;
Expand All @@ -48,6 +49,7 @@ pub async fn add_query(query: String) -> Result<(), ServerFnError> {
// TODO wierd leptos default naming convention
// get_query get the result of the last query
// ie get a list of images.
#[allow(clippy::unused_async)]
#[server]
pub async fn get_query(version: usize) -> Result<SearchResult, ServerFnError> {
use crate::pages::IMAGE_PREFIX;
Expand All @@ -62,24 +64,21 @@ pub async fn get_query(version: usize) -> Result<SearchResult, ServerFnError> {
let key = cantor_pair(version, i);

// Construct url from filename
let url = match path_rank
let url = path_rank
.0
.strip_prefix(state.selected_dir.clone())
{
Ok(filename) => {
format!(
"{IMAGE_PREFIX}{}",
filename.display().to_string()
)
}
Err(_) => String::default(),
};
.map_or_else(
|_| String::default(),
|filename| {
format!("{IMAGE_PREFIX}{}", filename.display())
},
);

let description =
match state.index.description_store.get(&url) {
Some(description) => description.to_string(),
None => String::default(),
};
let description = state
.index
.description_store
.get(&url)
.map_or_else(String::default, ToString::to_string);

SRElem {
description,
Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// <https://en.wikipedia.org/wiki/Pairing_function>
#[cfg(feature = "ssr")]
#[inline]
pub(crate) fn cantor_pair(k1: usize, k2: usize) -> usize {
pub(crate) const fn cantor_pair(k1: usize, k2: usize) -> usize {
(k1 + k2) * (k1 + k2 + 1) / 2 + k2
}

0 comments on commit 454aca6

Please sign in to comment.