treewide: replace std hashers with rustc_hash alternatives; fix clippy

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I766c36cb53d3d7f9e85b91a67c4131a66a6a6964
This commit is contained in:
raf 2026-03-19 22:34:30 +03:00
commit f831e58723
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
53 changed files with 343 additions and 394 deletions

View file

@ -1,8 +1,6 @@
use std::{
collections::{HashMap, HashSet},
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
use tracing::{info, warn};
@ -96,8 +94,8 @@ pub async fn detect_orphans(
let mut orphaned_ids = Vec::new();
// Build hash index: ContentHash -> Vec<(MediaId, PathBuf)>
let mut hash_index: HashMap<ContentHash, Vec<(MediaId, PathBuf)>> =
HashMap::new();
let mut hash_index: FxHashMap<ContentHash, Vec<(MediaId, PathBuf)>> =
FxHashMap::default();
for (id, path, hash) in &media_paths {
hash_index
.entry(hash.clone())
@ -138,12 +136,12 @@ pub async fn detect_orphans(
fn detect_moved_files(
orphaned_ids: &[MediaId],
media_paths: &[(MediaId, PathBuf, ContentHash)],
hash_index: &HashMap<ContentHash, Vec<(MediaId, PathBuf)>>,
hash_index: &FxHashMap<ContentHash, Vec<(MediaId, PathBuf)>>,
) -> Vec<(MediaId, PathBuf, PathBuf)> {
let mut moved = Vec::new();
// Build lookup map for orphaned items: MediaId -> (PathBuf, ContentHash)
let orphaned_map: HashMap<MediaId, (PathBuf, ContentHash)> = media_paths
let orphaned_map: FxHashMap<MediaId, (PathBuf, ContentHash)> = media_paths
.iter()
.filter(|(id, ..)| orphaned_ids.contains(id))
.map(|(id, path, hash)| (*id, (path.clone(), hash.clone())))
@ -184,7 +182,7 @@ async fn detect_untracked_files(
}
// Build set of tracked paths for fast lookup
let tracked_paths: HashSet<PathBuf> = media_paths
let tracked_paths: FxHashSet<PathBuf> = media_paths
.iter()
.map(|(_, path, _)| path.clone())
.collect();
@ -198,7 +196,7 @@ async fn detect_untracked_files(
];
// Walk filesystem for each root in parallel (limit concurrency to 4)
let mut filesystem_paths = HashSet::new();
let mut filesystem_paths = FxHashSet::default();
let mut tasks = tokio::task::JoinSet::new();
for root in roots {
@ -322,8 +320,7 @@ pub async fn verify_integrity(
let paths_to_check: Vec<(MediaId, PathBuf, ContentHash)> =
if let Some(ids) = media_ids {
let id_set: std::collections::HashSet<MediaId> =
ids.iter().copied().collect();
let id_set: FxHashSet<MediaId> = ids.iter().copied().collect();
all_paths
.into_iter()
.filter(|(id, ..)| id_set.contains(id))
@ -383,7 +380,7 @@ pub async fn cleanup_orphaned_thumbnails(
thumbnail_dir: &Path,
) -> Result<usize> {
let media_paths = storage.list_media_paths().await?;
let known_ids: std::collections::HashSet<String> = media_paths
let known_ids: FxHashSet<String> = media_paths
.iter()
.map(|(id, ..)| id.0.to_string())
.collect();