From 223405dcb902f42db37229df7a0b7bc3c6e2d4fe Mon Sep 17 00:00:00 2001 From: Petr Date: Fri, 26 Jun 2026 20:40:21 +0200 Subject: [PATCH] perf: invalidate Store cache on individual file mtime changes Previously the store only checked the content directory's own mtime, which does not change when an existing file is modified in place. Now track the newest mtime across all .md files as well, so edits picked up from disk (manual changes, git pull) are detected without a restart. --- lib/volumen/store.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/volumen/store.rb b/lib/volumen/store.rb index 17edfa7..1ba6595 100644 --- a/lib/volumen/store.rb +++ b/lib/volumen/store.rb @@ -20,10 +20,12 @@ module Volumen end def all - mtime = Dir.exist?(@content_dir) ? File.mtime(@content_dir) : nil - @all = nil if mtime != @all_mtime + current_dir_mtime = Dir.exist?(@content_dir) ? File.mtime(@content_dir) : nil + current_files_mtime = newest_file_mtime + @all = nil if current_dir_mtime != @all_dir_mtime || current_files_mtime != @all_files_mtime @all ||= begin - @all_mtime = mtime + @all_dir_mtime = current_dir_mtime + @all_files_mtime = current_files_mtime markdown_files.filter_map { |path| load_post(path) } end end @@ -79,6 +81,15 @@ module Volumen Dir.glob(File.join(@content_dir, "**", "*.md")) end + def newest_file_mtime + files = markdown_files + return nil if files.empty? + + files.map { |path| File.mtime(path) }.max + rescue SystemCallError + nil + end + def load_post(path) post = Post.parse(File.read(path)) post.metadata["slug"] ||= File.basename(path, ".md")