Memoize Site#post_attr_hash (#7276)

Merge pull request 7276
This commit is contained in:
Ashwin Maroli 2018-10-28 10:42:04 +05:30 committed by jekyllbot
parent 266a8bb746
commit ea8ac3a7fa
1 changed files with 8 additions and 5 deletions

View File

@ -92,6 +92,7 @@ module Jekyll
self.pages = []
self.static_files = []
self.data = {}
@post_attr_hash = {}
@site_data = nil
@collections = nil
@docs_to_write = nil
@ -232,6 +233,7 @@ module Jekyll
def post_attr_hash(post_attr)
# Build a hash map based on the specified post attribute ( post attr =>
# array of posts ) then sort each array in reverse order.
@post_attr_hash[post_attr] ||= begin
hash = Hash.new { |h, key| h[key] = [] }
posts.docs.each do |p|
p.data[post_attr]&.each { |t| hash[t] << p }
@ -239,6 +241,7 @@ module Jekyll
hash.each_value { |posts| posts.sort!.reverse! }
hash
end
end
def tags
post_attr_hash("tags")