mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-02 10:03:28 +00:00
Box heavy data inside enum (#2466)
* Box big data inside enum * Ignore size difference of Processed
This commit is contained in:
parent
e797b02e65
commit
8e994bedaa
|
@ -103,6 +103,9 @@ impl Task<Error> for ExtractFileMetadataTask {
|
|||
}
|
||||
|
||||
async fn run(&mut self, interrupter: &Interrupter) -> Result<ExecStatus, Error> {
|
||||
// `Processed` is larger than `Interrupt`, but it's much more common
|
||||
// so we ignore the size difference to optimize for usage
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum StreamMessage {
|
||||
Processed(Uuid, Result<FileMetadata, FileIOError>),
|
||||
Interrupt(InterruptionKind),
|
||||
|
|
|
@ -42,7 +42,7 @@ pub enum ExplorerItem {
|
|||
// this tells the frontend if a thumbnail actually exists or not
|
||||
has_created_thumbnail: bool,
|
||||
// we can't actually modify data from PCR types, thats why computed properties are used on ExplorerItem
|
||||
item: file_path_with_object::Data,
|
||||
item: Box<file_path_with_object::Data>,
|
||||
},
|
||||
Object {
|
||||
thumbnail: Option<ThumbnailKey>,
|
||||
|
@ -113,11 +113,8 @@ impl From<UserDirs> for SystemLocations {
|
|||
impl ExplorerItem {
|
||||
pub fn name(&self) -> &str {
|
||||
match self {
|
||||
ExplorerItem::Path {
|
||||
item: file_path_with_object::Data { name, .. },
|
||||
..
|
||||
}
|
||||
| ExplorerItem::Location {
|
||||
ExplorerItem::Path { item, .. } => item.name.as_deref().unwrap_or(""),
|
||||
ExplorerItem::Location {
|
||||
item: location::Data { name, .. },
|
||||
..
|
||||
} => name.as_deref().unwrap_or(""),
|
||||
|
@ -128,13 +125,8 @@ impl ExplorerItem {
|
|||
|
||||
pub fn size_in_bytes(&self) -> u64 {
|
||||
match self {
|
||||
ExplorerItem::Path {
|
||||
item: file_path_with_object::Data {
|
||||
size_in_bytes_bytes,
|
||||
..
|
||||
},
|
||||
..
|
||||
} => size_in_bytes_bytes
|
||||
ExplorerItem::Path { item, .. } => item
|
||||
.size_in_bytes_bytes
|
||||
.as_ref()
|
||||
.map(|size| {
|
||||
u64::from_be_bytes([
|
||||
|
@ -165,11 +157,10 @@ impl ExplorerItem {
|
|||
|
||||
pub fn date_created(&self) -> DateTime<Utc> {
|
||||
match self {
|
||||
ExplorerItem::Path {
|
||||
item: file_path_with_object::Data { date_created, .. },
|
||||
..
|
||||
ExplorerItem::Path { item, .. } => {
|
||||
item.date_created.map(Into::into).unwrap_or_default()
|
||||
}
|
||||
| ExplorerItem::Object {
|
||||
ExplorerItem::Object {
|
||||
item: object_with_file_paths::Data { date_created, .. },
|
||||
..
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ pub fn mount() -> AlphaRouter<Ctx> {
|
|||
// .filter(|_| thumbnail_exists_locally)
|
||||
.map(|i| get_indexed_thumb_key(i, library.id)),
|
||||
has_created_thumbnail,
|
||||
item: file_path,
|
||||
item: Box::new(file_path),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue