Skip to content

Commit

Permalink
fix: less filtering and more sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Feel-ix-343 committed Mar 2, 2024
1 parent 816d2d8 commit 9306147
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
9 changes: 8 additions & 1 deletion src/vault/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
)
}
Expand Down

0 comments on commit 9306147

Please sign in to comment.