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:
parent
0e79ba0518
commit
c6efd3661f
53 changed files with 343 additions and 394 deletions
|
|
@ -5,6 +5,7 @@ pub mod sqlite;
|
|||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use rustc_hash::FxHashMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -221,7 +222,7 @@ pub trait StorageBackend: Send + Sync + 'static {
|
|||
async fn get_custom_fields(
|
||||
&self,
|
||||
media_id: MediaId,
|
||||
) -> Result<std::collections::HashMap<String, CustomField>>;
|
||||
) -> Result<FxHashMap<String, CustomField>>;
|
||||
|
||||
/// Delete a custom field from a media item by name.
|
||||
async fn delete_custom_field(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use chrono::Utc;
|
||||
use deadpool_postgres::{Config as PoolConfig, Pool, Runtime};
|
||||
use native_tls::TlsConnector;
|
||||
use postgres_native_tls::MakeTlsConnector;
|
||||
use rustc_hash::FxHashMap;
|
||||
use tokio_postgres::{NoTls, Row, types::ToSql};
|
||||
use uuid::Uuid;
|
||||
|
||||
|
|
@ -215,7 +216,7 @@ fn row_to_media_item(row: &Row) -> Result<MediaItem> {
|
|||
thumbnail_path: row
|
||||
.get::<_, Option<String>>("thumbnail_path")
|
||||
.map(PathBuf::from),
|
||||
custom_fields: HashMap::new(),
|
||||
custom_fields: FxHashMap::default(),
|
||||
file_mtime: row.get("file_mtime"),
|
||||
|
||||
// Photo-specific fields
|
||||
|
|
@ -922,8 +923,8 @@ impl StorageBackend for PostgresBackend {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -1596,8 +1597,8 @@ impl StorageBackend for PostgresBackend {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -1759,8 +1760,8 @@ impl StorageBackend for PostgresBackend {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -1894,7 +1895,7 @@ impl StorageBackend for PostgresBackend {
|
|||
async fn get_custom_fields(
|
||||
&self,
|
||||
media_id: MediaId,
|
||||
) -> Result<HashMap<String, CustomField>> {
|
||||
) -> Result<FxHashMap<String, CustomField>> {
|
||||
let client = self
|
||||
.pool
|
||||
.get()
|
||||
|
|
@ -1909,7 +1910,7 @@ impl StorageBackend for PostgresBackend {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let mut map = HashMap::new();
|
||||
let mut map = FxHashMap::default();
|
||||
for row in &rows {
|
||||
let name: String = row.get("field_name");
|
||||
let ft_str: String = row.get("field_type");
|
||||
|
|
@ -1988,8 +1989,8 @@ impl StorageBackend for PostgresBackend {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -2066,8 +2067,8 @@ impl StorageBackend for PostgresBackend {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -2089,8 +2090,8 @@ impl StorageBackend for PostgresBackend {
|
|||
|
||||
// Compare each pair and build groups
|
||||
let mut groups: Vec<Vec<MediaItem>> = Vec::new();
|
||||
let mut grouped_indices: std::collections::HashSet<usize> =
|
||||
std::collections::HashSet::new();
|
||||
let mut grouped_indices: rustc_hash::FxHashSet<usize> =
|
||||
rustc_hash::FxHashSet::default();
|
||||
|
||||
for i in 0..items.len() {
|
||||
if grouped_indices.contains(&i) {
|
||||
|
|
@ -2952,8 +2953,8 @@ impl StorageBackend for PostgresBackend {
|
|||
&[&ids],
|
||||
)
|
||||
.await?;
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -3365,8 +3366,8 @@ impl StorageBackend for PostgresBackend {
|
|||
&[&ids],
|
||||
)
|
||||
.await?;
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -3553,8 +3554,8 @@ impl StorageBackend for PostgresBackend {
|
|||
&[&ids],
|
||||
)
|
||||
.await?;
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -3623,8 +3624,8 @@ impl StorageBackend for PostgresBackend {
|
|||
&[&ids],
|
||||
)
|
||||
.await?;
|
||||
let mut cf_map: HashMap<Uuid, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut cf_map: FxHashMap<Uuid, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for row in &cf_rows {
|
||||
let mid: Uuid = row.get("media_id");
|
||||
let name: String = row.get("field_name");
|
||||
|
|
@ -4448,8 +4449,7 @@ impl StorageBackend for PostgresBackend {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let mut identifiers: std::collections::HashMap<String, Vec<String>> =
|
||||
std::collections::HashMap::new();
|
||||
let mut identifiers: FxHashMap<String, Vec<String>> = FxHashMap::default();
|
||||
for r in id_rows {
|
||||
let id_type: String = r.get(0);
|
||||
let value: String = r.get(1);
|
||||
|
|
@ -7031,11 +7031,11 @@ impl StorageBackend for PostgresBackend {
|
|||
let depth = depth.min(5); // Limit depth
|
||||
let mut nodes = Vec::new();
|
||||
let mut edges = Vec::new();
|
||||
let node_ids: std::collections::HashSet<String> =
|
||||
let node_ids: rustc_hash::FxHashSet<String> =
|
||||
if let Some(center) = center_id {
|
||||
// BFS to find connected nodes within depth
|
||||
let mut frontier = vec![center.0.to_string()];
|
||||
let mut visited = std::collections::HashSet::new();
|
||||
let mut visited = rustc_hash::FxHashSet::default();
|
||||
visited.insert(center.0.to_string());
|
||||
|
||||
for _ in 0..depth {
|
||||
|
|
@ -7099,7 +7099,7 @@ impl StorageBackend for PostgresBackend {
|
|||
.await
|
||||
.map_err(|e| PinakesError::Database(e.to_string()))?;
|
||||
|
||||
let mut collected = std::collections::HashSet::new();
|
||||
let mut collected = rustc_hash::FxHashSet::default();
|
||||
for row in rows {
|
||||
let id: String = row.get(0);
|
||||
collected.insert(id);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use rusqlite::{Connection, Row, params};
|
||||
use rustc_hash::FxHashMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -142,7 +142,7 @@ fn row_to_media_item(row: &Row) -> rusqlite::Result<MediaItem> {
|
|||
thumbnail_path: row
|
||||
.get::<_, Option<String>>("thumbnail_path")?
|
||||
.map(PathBuf::from),
|
||||
custom_fields: HashMap::new(), // loaded separately
|
||||
custom_fields: FxHashMap::default(), // loaded separately
|
||||
// file_mtime may not be present in all queries, so handle gracefully
|
||||
file_mtime: row.get::<_, Option<i64>>("file_mtime").unwrap_or(None),
|
||||
|
||||
|
|
@ -358,7 +358,7 @@ fn load_user_profile_sync(
|
|||
fn load_custom_fields_sync(
|
||||
db: &Connection,
|
||||
media_id: MediaId,
|
||||
) -> rusqlite::Result<HashMap<String, CustomField>> {
|
||||
) -> rusqlite::Result<FxHashMap<String, CustomField>> {
|
||||
let mut stmt = db.prepare(
|
||||
"SELECT field_name, field_type, field_value FROM custom_fields WHERE \
|
||||
media_id = ?1",
|
||||
|
|
@ -372,7 +372,7 @@ fn load_custom_fields_sync(
|
|||
value,
|
||||
}))
|
||||
})?;
|
||||
let mut map = HashMap::new();
|
||||
let mut map = FxHashMap::default();
|
||||
for r in rows {
|
||||
let (name, field) = r?;
|
||||
map.insert(name, field);
|
||||
|
|
@ -409,8 +409,8 @@ fn load_custom_fields_batch(
|
|||
Ok((mid_str, name, ft_str, value))
|
||||
})?;
|
||||
|
||||
let mut fields_map: HashMap<String, HashMap<String, CustomField>> =
|
||||
HashMap::new();
|
||||
let mut fields_map: FxHashMap<String, FxHashMap<String, CustomField>> =
|
||||
FxHashMap::default();
|
||||
for r in rows {
|
||||
let (mid_str, name, ft_str, value) = r?;
|
||||
fields_map
|
||||
|
|
@ -1762,7 +1762,7 @@ impl StorageBackend for SqliteBackend {
|
|||
async fn get_custom_fields(
|
||||
&self,
|
||||
media_id: MediaId,
|
||||
) -> Result<HashMap<String, CustomField>> {
|
||||
) -> Result<FxHashMap<String, CustomField>> {
|
||||
let conn = Arc::clone(&self.conn);
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let map = {
|
||||
|
|
@ -1783,7 +1783,7 @@ impl StorageBackend for SqliteBackend {
|
|||
}))
|
||||
})?;
|
||||
|
||||
let mut map = HashMap::new();
|
||||
let mut map = FxHashMap::default();
|
||||
for r in rows {
|
||||
let (name, field) = r?;
|
||||
map.insert(name, field);
|
||||
|
|
@ -2093,8 +2093,8 @@ impl StorageBackend for SqliteBackend {
|
|||
|
||||
// Compare each pair and build groups
|
||||
let mut groups: Vec<Vec<MediaItem>> = Vec::new();
|
||||
let mut grouped_indices: std::collections::HashSet<usize> =
|
||||
std::collections::HashSet::new();
|
||||
let mut grouped_indices: rustc_hash::FxHashSet<usize> =
|
||||
rustc_hash::FxHashSet::default();
|
||||
|
||||
for i in 0..items.len() {
|
||||
if grouped_indices.contains(&i) {
|
||||
|
|
@ -5265,8 +5265,8 @@ impl StorageBackend for SqliteBackend {
|
|||
"SELECT identifier_type, identifier_value
|
||||
FROM book_identifiers WHERE media_id = ?1",
|
||||
)?;
|
||||
let mut identifiers: std::collections::HashMap<String, Vec<String>> =
|
||||
std::collections::HashMap::new();
|
||||
let mut identifiers: FxHashMap<String, Vec<String>> =
|
||||
FxHashMap::default();
|
||||
for row in stmt.query_map([&media_id_str], |row| {
|
||||
Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?))
|
||||
})? {
|
||||
|
|
@ -8336,13 +8336,13 @@ impl StorageBackend for SqliteBackend {
|
|||
let conn = conn.lock().map_err(|e| PinakesError::Database(format!("connection mutex poisoned: {e}")))?;
|
||||
let mut nodes = Vec::new();
|
||||
let mut edges = Vec::new();
|
||||
let mut node_ids = std::collections::HashSet::new();
|
||||
let mut node_ids = rustc_hash::FxHashSet::default();
|
||||
|
||||
// Get nodes - either all markdown files or those connected to center
|
||||
if let Some(center_id) = center_id_str {
|
||||
// BFS to find connected nodes within depth
|
||||
let mut frontier = vec![center_id.clone()];
|
||||
let mut visited = std::collections::HashSet::new();
|
||||
let mut visited = rustc_hash::FxHashSet::default();
|
||||
visited.insert(center_id);
|
||||
|
||||
for _ in 0..depth {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue