Two massive performance improvements for large sites (#6730)
Merge pull request 6730
This commit is contained in:
		
							parent
							
								
									138a12c481
								
							
						
					
					
						commit
						b4985d1e63
					
				| 
						 | 
					@ -358,7 +358,7 @@ module Jekyll
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns an Array of related Posts.
 | 
					    # Returns an Array of related Posts.
 | 
				
			||||||
    def related_posts
 | 
					    def related_posts
 | 
				
			||||||
      Jekyll::RelatedPosts.new(self).build
 | 
					      @related_posts ||= Jekyll::RelatedPosts.new(self).build
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Override of normal respond_to? to match method_missing's logic for
 | 
					    # Override of normal respond_to? to match method_missing's logic for
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,6 +37,16 @@ module Jekyll
 | 
				
			||||||
        @site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
 | 
					        @site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
 | 
				
			||||||
      end
 | 
					      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)
 | 
				
			||||||
 | 
					        @current_document.related_posts
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      attr_writer :current_document
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      # return nil for `{{ site.config }}` even if --config was passed via CLI
 | 
					      # return nil for `{{ site.config }}` even if --config was passed via CLI
 | 
				
			||||||
      def config; end
 | 
					      def config; end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ module Jekyll
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def most_recent_posts
 | 
					    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
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,7 @@ module Jekyll
 | 
				
			||||||
      Jekyll.logger.debug "Rendering:", document.relative_path
 | 
					      Jekyll.logger.debug "Rendering:", document.relative_path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      assign_pages!
 | 
					      assign_pages!
 | 
				
			||||||
      assign_related_posts!
 | 
					      assign_current_document!
 | 
				
			||||||
      assign_highlighter_options!
 | 
					      assign_highlighter_options!
 | 
				
			||||||
      assign_layout_data!
 | 
					      assign_layout_data!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -217,12 +217,8 @@ module Jekyll
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns nothing
 | 
					    # Returns nothing
 | 
				
			||||||
    private
 | 
					    private
 | 
				
			||||||
    def assign_related_posts!
 | 
					    def assign_current_document!
 | 
				
			||||||
      if document.is_a?(Document) && document.collection.label == "posts"
 | 
					      payload["site"].current_document = document
 | 
				
			||||||
        payload["site"]["related_posts"] = document.related_posts
 | 
					 | 
				
			||||||
      else
 | 
					 | 
				
			||||||
        payload["site"]["related_posts"] = nil
 | 
					 | 
				
			||||||
      end
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Set highlighter prefix and suffix
 | 
					    # Set highlighter prefix and suffix
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue