Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two massive performance improvements for large sites #6730

Merged
merged 2 commits into from Jan 31, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -358,7 +358,7 @@ def id
#
# Returns an Array of related Posts.
def related_posts
Jekyll::RelatedPosts.new(self).build
@related_posts ||= Jekyll::RelatedPosts.new(self).build
end

# Override of normal respond_to? to match method_missing's logic for
@@ -37,6 +37,16 @@ def collections
@site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
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.
# We should remove this in 4.0 and switch to `{{ post.related_posts }}`.
def related_posts
return nil unless @current_document.is_a?(Jekyll::Document)

This comment has been minimized.

Copy link
@ashmaroli

ashmaroli Jan 31, 2018

Member

can we also return early if the current document is not a Post..?
Like for a site with two posts and another collection with 1000 documents..?

This comment has been minimized.

Copy link
@pathawks

pathawks Jan 31, 2018

Member

can we also return early if the current document is not a Post..?

I don't think so. A site could be using site.related_posts on a Document to display the most recent blog posts.

This comment has been minimized.

Copy link
@ashmaroli

ashmaroli Jan 31, 2018

Member

good point.. 👍

@current_document.related_posts
end
attr_writer :current_document

# return nil for `{{ site.config }}` even if --config was passed via CLI
def config; end

@@ -46,7 +46,7 @@ def lsi_related_posts
end

def most_recent_posts
@most_recent_posts ||= (site.posts.docs.reverse - [post]).first(10)
@most_recent_posts ||= (site.posts.docs.last(11).reverse - [post]).first(10)
end
end
end
@@ -52,7 +52,7 @@ def run
Jekyll.logger.debug "Rendering:", document.relative_path

assign_pages!
assign_related_posts!
assign_current_document!
assign_highlighter_options!
assign_layout_data!

@@ -217,12 +217,8 @@ def assign_pages!
#
# Returns nothing
private
def assign_related_posts!
if document.is_a?(Document) && document.collection.label == "posts"
payload["site"]["related_posts"] = document.related_posts
else
payload["site"]["related_posts"] = nil
end
def assign_current_document!
payload["site"].current_document = document
end

# Set highlighter prefix and suffix
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.