perf: memoize published_posts within a single request

Store the filtered and sorted list of published posts in an instance
variable so repeated calls during the same request (posts list, tags,
feeds, sitemap) reuse the cached result instead of re-filtering and
re-sorting from scratch each time. Sinatra resets instance variables
between requests, so the cache stays fresh.
This commit is contained in:
2026-06-26 20:34:37 +02:00
parent 5437cef1cd
commit 4abb5585df
+2 -2
View File
@@ -79,8 +79,8 @@ module Volumen
end end
def published_posts def published_posts
store.all.reject { |post| post.draft? || post.scheduled? } @published_posts ||= store.all.reject { |post| post.draft? || post.scheduled? }
.sort_by { |post| post.date_string || "" }.reverse .sort_by { |post| post.date_string || "" }.reverse
end end
def site_payload def site_payload