Log deduping

This commit is contained in:
Andras Schmelczer 2025-11-30 11:23:37 +00:00
parent 896014bf38
commit acffd0006d

View file

@ -1,6 +1,7 @@
use crate::app_state::database::models::VaultId; use crate::app_state::database::models::VaultId;
use crate::{app_state::database::Transaction, utils::dedup_paths::dedup_paths}; use crate::{app_state::database::Transaction, utils::dedup_paths::dedup_paths};
use anyhow::Result; use anyhow::Result;
use log::{debug, info};
pub async fn find_first_available_path( pub async fn find_first_available_path(
vault_id: &VaultId, vault_id: &VaultId,
@ -8,12 +9,15 @@ pub async fn find_first_available_path(
database: &crate::app_state::database::Database, database: &crate::app_state::database::Database,
transaction: &mut Transaction<'_>, transaction: &mut Transaction<'_>,
) -> Result<String> { ) -> Result<String> {
info!("Finding first available path for `{sanitized_relative_path}` in vault `{vault_id}`");
for candidate in dedup_paths(sanitized_relative_path) { for candidate in dedup_paths(sanitized_relative_path) {
debug!("Checking candidate path for deconflicting names: `{candidate}`");
if database if database
.get_latest_document_by_path(vault_id, &candidate, Some(transaction)) .get_latest_document_by_path(vault_id, &candidate, Some(transaction))
.await? .await?
.is_none() .is_none()
{ {
info!("Selected available path: `{candidate}`");
return Ok(candidate); return Ok(candidate);
} }
} }