Memoize SiteDrop#documents to reduce allocations (#7697)

Merge pull request 7697
This commit is contained in:
Ashwin Maroli 2019-06-26 02:32:04 +05:30 committed by jekyllbot
parent 7d340d933a
commit 27aa53cf82
1 changed files with 11 additions and 1 deletions

View File

@ -8,7 +8,7 @@ module Jekyll
mutable false
def_delegator :@obj, :site_data, :data
def_delegators :@obj, :time, :pages, :static_files, :documents, :tags, :categories
def_delegators :@obj, :time, :pages, :static_files, :tags, :categories
private def_delegator :@obj, :config, :fallback_data
@ -38,6 +38,16 @@ module Jekyll
@site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
end
# `Site#documents` cannot be memoized so that `Site#docs_to_write` can access the
# latest state of the attribute.
#
# Since this method will be called after `Site#pre_render` hook, the `Site#documents`
# array shouldn't thereafter change and can therefore be safely memoized to prevent
# additional computation of `Site#documents`.
def documents
@documents ||= @obj.documents
end
# `{{ site.related_posts }}` is how posts can get posts related to
# them, either through LSI if it's enabled, or through the most
# recent posts.