Perf improvements
This commit is contained in:
parent
e6483cf138
commit
a4baa2c792
4 changed files with 28 additions and 18 deletions
|
@ -3,7 +3,7 @@ use std::{
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use lasso2::ThreadedRodeo;
|
use lasso2::{RodeoReader, ThreadedRodeo};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
@ -200,13 +200,23 @@ impl Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Index {
|
pub struct Index {
|
||||||
pub strings: ThreadedRodeo,
|
pub strings: RodeoReader,
|
||||||
pub browser: browser::Browser,
|
pub browser: browser::Browser,
|
||||||
pub collection: collection::Collection,
|
pub collection: collection::Collection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Index {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
strings: ThreadedRodeo::new().into_reader(),
|
||||||
|
browser: Default::default(),
|
||||||
|
collection: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
strings: ThreadedRodeo,
|
strings: ThreadedRodeo,
|
||||||
browser_builder: browser::Builder,
|
browser_builder: browser::Builder,
|
||||||
|
@ -236,7 +246,7 @@ impl Builder {
|
||||||
Index {
|
Index {
|
||||||
browser: self.browser_builder.build(),
|
browser: self.browser_builder.build(),
|
||||||
collection: self.collection_builder.build(),
|
collection: self.collection_builder.build(),
|
||||||
strings: self.strings,
|
strings: self.strings.into_reader(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use lasso2::ThreadedRodeo;
|
use lasso2::{RodeoReader, ThreadedRodeo};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tinyvec::TinyVec;
|
use tinyvec::TinyVec;
|
||||||
use trie_rs::{Trie, TrieBuilder};
|
use trie_rs::{Trie, TrieBuilder};
|
||||||
|
@ -40,7 +40,7 @@ impl Default for Browser {
|
||||||
impl Browser {
|
impl Browser {
|
||||||
pub fn browse<P: AsRef<Path>>(
|
pub fn browse<P: AsRef<Path>>(
|
||||||
&self,
|
&self,
|
||||||
strings: &ThreadedRodeo,
|
strings: &RodeoReader,
|
||||||
virtual_path: P,
|
virtual_path: P,
|
||||||
) -> Result<Vec<File>, Error> {
|
) -> Result<Vec<File>, Error> {
|
||||||
let path = virtual_path
|
let path = virtual_path
|
||||||
|
@ -70,7 +70,7 @@ impl Browser {
|
||||||
|
|
||||||
pub fn flatten<P: AsRef<Path>>(
|
pub fn flatten<P: AsRef<Path>>(
|
||||||
&self,
|
&self,
|
||||||
strings: &ThreadedRodeo,
|
strings: &RodeoReader,
|
||||||
virtual_path: P,
|
virtual_path: P,
|
||||||
) -> Result<Vec<PathBuf>, Error> {
|
) -> Result<Vec<PathBuf>, Error> {
|
||||||
let path_components = virtual_path
|
let path_components = virtual_path
|
||||||
|
@ -87,7 +87,7 @@ impl Browser {
|
||||||
Ok(self
|
Ok(self
|
||||||
.flattened
|
.flattened
|
||||||
.predictive_search(path_components)
|
.predictive_search(path_components)
|
||||||
.map(|c: Vec<_>| -> PathBuf {
|
.map(|c: TinyVec<[_; 8]>| -> PathBuf {
|
||||||
c.into_iter()
|
c.into_iter()
|
||||||
.map(|s| strings.resolve(&s))
|
.map(|s| strings.resolve(&s))
|
||||||
.collect::<TinyVec<[&str; 8]>>()
|
.collect::<TinyVec<[&str; 8]>>()
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
use lasso2::ThreadedRodeo;
|
use lasso2::{RodeoReader, ThreadedRodeo};
|
||||||
use rand::{rngs::ThreadRng, seq::IteratorRandom};
|
use rand::{rngs::ThreadRng, seq::IteratorRandom};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ pub struct Collection {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn get_artist(&self, strings: &ThreadedRodeo, artist_key: ArtistKey) -> Option<Artist> {
|
pub fn get_artist(&self, strings: &RodeoReader, artist_key: ArtistKey) -> Option<Artist> {
|
||||||
self.artists.get(&artist_key).map(|a| {
|
self.artists.get(&artist_key).map(|a| {
|
||||||
let albums = {
|
let albums = {
|
||||||
let mut albums = a
|
let mut albums = a
|
||||||
|
@ -94,7 +94,7 @@ impl Collection {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_album(&self, strings: &ThreadedRodeo, album_key: AlbumKey) -> Option<Album> {
|
pub fn get_album(&self, strings: &RodeoReader, album_key: AlbumKey) -> Option<Album> {
|
||||||
self.albums.get(&album_key).map(|a| {
|
self.albums.get(&album_key).map(|a| {
|
||||||
let mut songs = a
|
let mut songs = a
|
||||||
.songs
|
.songs
|
||||||
|
@ -130,7 +130,7 @@ impl Collection {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_random_albums(&self, strings: &ThreadedRodeo, count: usize) -> Vec<Album> {
|
pub fn get_random_albums(&self, strings: &RodeoReader, count: usize) -> Vec<Album> {
|
||||||
self.albums
|
self.albums
|
||||||
.keys()
|
.keys()
|
||||||
.choose_multiple(&mut ThreadRng::default(), count)
|
.choose_multiple(&mut ThreadRng::default(), count)
|
||||||
|
@ -139,7 +139,7 @@ impl Collection {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_recent_albums(&self, strings: &ThreadedRodeo, count: usize) -> Vec<Album> {
|
pub fn get_recent_albums(&self, strings: &RodeoReader, count: usize) -> Vec<Album> {
|
||||||
self.recent_albums
|
self.recent_albums
|
||||||
.iter()
|
.iter()
|
||||||
.take(count)
|
.take(count)
|
||||||
|
@ -147,7 +147,7 @@ impl Collection {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_song(&self, strings: &ThreadedRodeo, song_key: SongKey) -> Option<Song> {
|
pub fn get_song(&self, strings: &RodeoReader, song_key: SongKey) -> Option<Song> {
|
||||||
self.songs.get(&song_key).map(|s| fetch_song(strings, s))
|
self.songs.get(&song_key).map(|s| fetch_song(strings, s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use lasso2::ThreadedRodeo;
|
use lasso2::{RodeoReader, ThreadedRodeo};
|
||||||
use log::error;
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tinyvec::TinyVec;
|
use tinyvec::TinyVec;
|
||||||
|
@ -149,7 +149,7 @@ pub fn store_song(strings: &mut ThreadedRodeo, song: &scanner::Song) -> Option<S
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_song(strings: &ThreadedRodeo, song: &Song) -> super::Song {
|
pub fn fetch_song(strings: &RodeoReader, song: &Song) -> super::Song {
|
||||||
super::Song {
|
super::Song {
|
||||||
path: PathBuf::from(strings.resolve(&song.path.0)),
|
path: PathBuf::from(strings.resolve(&song.path.0)),
|
||||||
virtual_path: PathBuf::from(strings.resolve(&song.virtual_path.0)),
|
virtual_path: PathBuf::from(strings.resolve(&song.virtual_path.0)),
|
||||||
|
@ -197,7 +197,7 @@ pub fn fetch_song(strings: &ThreadedRodeo, song: &Song) -> super::Song {
|
||||||
|
|
||||||
pub trait InternPath {
|
pub trait InternPath {
|
||||||
fn get_or_intern(self, strings: &mut ThreadedRodeo) -> Option<PathKey>;
|
fn get_or_intern(self, strings: &mut ThreadedRodeo) -> Option<PathKey>;
|
||||||
fn get(self, strings: &ThreadedRodeo) -> Option<PathKey>;
|
fn get(self, strings: &RodeoReader) -> Option<PathKey>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: AsRef<Path>> InternPath for P {
|
impl<P: AsRef<Path>> InternPath for P {
|
||||||
|
@ -214,7 +214,7 @@ impl<P: AsRef<Path>> InternPath for P {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(self, strings: &ThreadedRodeo) -> Option<PathKey> {
|
fn get(self, strings: &RodeoReader) -> Option<PathKey> {
|
||||||
let id = self
|
let id = self
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
|
|
Loading…
Add table
Reference in a new issue