Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 150 additions & 8 deletions rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ edition = "2021"

[dependencies]
actix-web = "^4"
bincode = "^3"
clap = { version = "^4", features = ["derive"] }
env_logger = "^0"
log = "^0"
Expand All @@ -23,6 +22,7 @@ rand = "^0"
regex = "^1"
lazy_static = "^1"
once_cell = "^1"
rkyv = "^0.8"

[dev-dependencies]
assert_matches = "^1"
Expand Down
15 changes: 9 additions & 6 deletions rs/src/filemanager/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use rkyv::from_bytes;
use rkyv::{rancor::Error, Archive, Deserialize, Serialize};
use std::collections::{hash_map::DefaultHasher, HashSet};
use std::fs;
use std::hash::{Hash, Hasher};
Expand All @@ -11,7 +12,7 @@ use super::options::CollectionOptions;
static DB_ROOT_PATH: &str = ".cache";
const DEFAULT_IGNORES: [&str; 2] = ["Music", "Audio Music Apps"];

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Archive)]
struct File {
path: String,
id: String,
Expand Down Expand Up @@ -84,16 +85,18 @@ fn db_to_files(db: sled::Db) -> Vec<PathBuf> {
}

fn deserialize(bytes: &[u8]) -> File {
let decoded: File = bincode::deserialize(bytes).unwrap();
decoded
//let decoded: File = bincode::deserialize(bytes).unwrap();
let deserialized: File = from_bytes::<File, Error>(bytes).unwrap();
deserialized
}

fn serialize(path: PathBuf, id: String) -> Vec<u8> {
let file = File {
path: path.to_str().unwrap().to_string(),
id,
};
bincode::serialize(&file).unwrap()
//bincode::serialize(&file).unwrap()
rkyv::to_bytes::<Error>(&file).unwrap().into_vec()
}

fn walk_dirs(dir: String, db: &mut sled::Db, ignores: HashSet<String>) {
Expand All @@ -116,7 +119,7 @@ fn walk_dirs(dir: String, db: &mut sled::Db, ignores: HashSet<String>) {
let encoded = serialize(path, id);
db.insert(i.to_be_bytes(), encoded).unwrap();
i += 1;
if i % 500 == 0 {
if i.is_multiple_of(500) {
log::info!("{}", i);
}
}
Expand Down
Loading