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.
This commit is contained in:
+14
-3
@@ -20,10 +20,12 @@ module Volumen
|
|||||||
end
|
end
|
||||||
|
|
||||||
def all
|
def all
|
||||||
mtime = Dir.exist?(@content_dir) ? File.mtime(@content_dir) : nil
|
current_dir_mtime = Dir.exist?(@content_dir) ? File.mtime(@content_dir) : nil
|
||||||
@all = nil if mtime != @all_mtime
|
current_files_mtime = newest_file_mtime
|
||||||
|
@all = nil if current_dir_mtime != @all_dir_mtime || current_files_mtime != @all_files_mtime
|
||||||
@all ||= begin
|
@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) }
|
markdown_files.filter_map { |path| load_post(path) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -79,6 +81,15 @@ module Volumen
|
|||||||
Dir.glob(File.join(@content_dir, "**", "*.md"))
|
Dir.glob(File.join(@content_dir, "**", "*.md"))
|
||||||
end
|
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)
|
def load_post(path)
|
||||||
post = Post.parse(File.read(path))
|
post = Post.parse(File.read(path))
|
||||||
post.metadata["slug"] ||= File.basename(path, ".md")
|
post.metadata["slug"] ||= File.basename(path, ".md")
|
||||||
|
|||||||
Reference in New Issue
Block a user