From 93061476b64a45db28e3015569ce8ab414a9d8fd Mon Sep 17 00:00:00 2001 From: Felix Zeller Date: Sat, 2 Mar 2024 01:04:49 -0500 Subject: [PATCH] fix: less filtering and more sorting --- src/ui.rs | 9 +-------- src/vault/mod.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index d333c45f..cece9c55 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -23,14 +23,7 @@ fn referenceable_string(vault: &Vault, referenceable: &Referenceable) -> Option< let backlinks_preview = match vault.select_references_for_referenceable(referenceable) { Some(references) => references.into_iter() - .take(20) - .map(|(path, reference)| match std::fs::metadata(path).and_then(|meta| meta.modified()) { - Ok(modified) => (path, reference, modified), - Err(_) => (path, reference, SystemTime::UNIX_EPOCH), - }) - .sorted_by_key(|(_, _, modified)| *modified) - .rev() - .flat_map(|(path, reference, _)| { + .flat_map(|(path, reference)| { let line = String::from_iter(vault.select_line(path, reference.data().range.start.line as isize)?); let path = get_obsidian_ref_path(&vault.root_dir(), path)?; diff --git a/src/vault/mod.rs b/src/vault/mod.rs index 4a8f1ef0..95e74c0a 100644 --- a/src/vault/mod.rs +++ b/src/vault/mod.rs @@ -3,7 +3,7 @@ use std::{ hash::Hash, iter, ops::{Deref, DerefMut, Range, Not}, - path::{Path, PathBuf}, char, + path::{Path, PathBuf}, char, time::SystemTime, }; use itertools::Itertools; @@ -293,6 +293,13 @@ impl Vault { .filter(|(ref_path, reference)| { referenceable.matches_reference(&self.root_dir, reference, ref_path) }) + .map(|(path, reference)| match std::fs::metadata(path).and_then(|meta| meta.modified()) { + Ok(modified) => (path, reference, modified), + Err(_) => (path, reference, SystemTime::UNIX_EPOCH), + }) + .sorted_by_key(|(_, _, modified)| *modified) + .rev() + .map(|(one, two, _)| (one, two)) .collect(), ) }