Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caching to obsidian-list-all-files function #47

Merged
merged 6 commits into from
Jul 2, 2023
Merged

Add caching to obsidian-list-all-files function #47

merged 6 commits into from
Jul 2, 2023

Conversation

kdmsnr
Copy link
Contributor

@kdmsnr kdmsnr commented Jun 30, 2023

This PR adds a caching mechanism to the obsidian-list-all-files function to improve its performance. The function now only scans the Obsidian directory once and subsequently uses the stored result. A new function, obsidian-clear-cache, is introduced to manually clear the cache when necessary.

ref. #39

@licht1stein
Copy link
Owner

Hey, thanks for the PR! One question, do you update the cache when creating new notes?

@kdmsnr
Copy link
Contributor Author

kdmsnr commented Jul 1, 2023

Hi, thank you for your review! Based on your feedback, I've now adjusted the code so that the cache is also cleared when a note is saved. This ensures that the cache will always be updated when changes are made to the notes. I have committed this change. Please take a look!

@licht1stein
Copy link
Owner

Great! There's another case of new file being created, when following a link to a yet non existent file using obsidian-find-file, probably we should cover this case as well and invalidate cache if the file doesn't yet exist.

@licht1stein
Copy link
Owner

Does the hook that you add only work in obsidian-mode? Maybe instead of the hook we can just invalidate cache directly? The current way the hook will just stay there, wouldn't it?

@kdmsnr
Copy link
Contributor Author

kdmsnr commented Jul 1, 2023

Based on your feedback, I've made adjustments to ensure the cache gets invalidated not only on note creation but also when following a link to a non-existent note etc.

I've also addressed the concern about the after-save-hook lingering by making it self-removing after it gets triggered once. This ensures that the cache is cleared only when a new note gets saved for the first time.

I've pushed these changes and updated the PR. Please take a look! I'm not fully versed in elisp, so I would really appreciate it if you could review this.

@kdmsnr
Copy link
Contributor Author

kdmsnr commented Jul 1, 2023

Sorry for the confusion, I've reconsidered and understand now. This PR modifies obsidian-capture and obsidian-find-file to clear the cache before creating new files. This ensures that the cache is always up to date, without the need for hooks.

@licht1stein
Copy link
Owner

Great, thank you! I'll add a few final touches and bump the version :)

@licht1stein licht1stein merged commit 3d63b9c into licht1stein:master Jul 2, 2023
@licht1stein
Copy link
Owner

I broke down the logic into smaller pieces, please check that everything works :)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants