Skip to content

Commit

Permalink
fix(scanner): Always sort tagged file collections by path
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Oct 31, 2024
1 parent f1fa141 commit 7695cb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::release_candidate::ReleaseCandidateCollection;
use crate::util::walk_dir;
use crate::Cache;
use crate::{Config, TaggedFile, TaggedFileCollection};
use std::collections::{HashMap, HashSet};
use std::collections::{BinaryHeap, HashMap, HashSet};
use std::path::PathBuf;
use std::time::Duration;
use tokio::sync::mpsc::{error::TryRecvError, Receiver};
Expand Down Expand Up @@ -103,7 +103,7 @@ impl Scanner {
};

group_track_counts.insert(group_id, num_tracks);
group_tracks.insert(group_id, Vec::with_capacity(num_tracks));
group_tracks.insert(group_id, BinaryHeap::with_capacity(num_tracks));
}

while analyzer_output_rx_connected {
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Scanner {
continue;
};

let collection = TaggedFileCollection::new(tracks);
let collection = TaggedFileCollection::new(tracks.into_sorted_vec());
if let Err(err) = post_analysis_tx.send(collection).await {
log::error!("Receiver dropped on sending collection: {err}");
continue;
Expand All @@ -159,7 +159,7 @@ impl Scanner {
log::error!("Missing track count for group {group_id}");
}

let collection = TaggedFileCollection::new(tracks);
let collection = TaggedFileCollection::new(tracks.into_sorted_vec());
if let Err(err) = post_analysis_tx.send(collection).await {
log::error!("Receiver dropped on sending collection: {err}");
}
Expand Down
21 changes: 21 additions & 0 deletions src/taggedfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::release::ReleaseLike;
use crate::tag::{read_tags_from_path, Tag, TagKey};
use crate::track::{AnalyzedTrackMetadata, TrackLike};
use std::borrow::Cow;
use std::cmp::Ordering;
use std::ffi::OsStr;
use std::fmt;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -269,6 +270,26 @@ impl TaggedFile {
}
}

impl PartialEq for TaggedFile {
fn eq(&self, other: &Self) -> bool {
self.path.as_path().eq(other.path.as_path())
}
}

impl Eq for TaggedFile {}

impl Ord for TaggedFile {
fn cmp(&self, other: &Self) -> Ordering {
self.path.as_path().cmp(other.path.as_path())
}
}

impl PartialOrd for TaggedFile {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl TrackLike for TaggedFile {
fn acoustid(&self) -> Option<Cow<'_, str>> {
self.first_tag_value(TagKey::AcoustId).map(Cow::from)
Expand Down

0 comments on commit 7695cb6

Please sign in to comment.