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
Glob scope path only if configured with a pattern #6692
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👏 LGTM! Might be worth adding a test to check that Dir.glob
is no longer called for pattern-less paths?
Also can you confirm that this speeds up https://github.com/mmistakes/front-matter-defaults.git again?
On latest macOS with my macbook air and @mmistakes test repo:
|
Tested the fix on the front-matter-defaults repo and my large personal site... both are back to building at 😄 |
lib/jekyll/frontmatter_defaults.rb
Outdated
@@ -123,6 +128,13 @@ def path_is_subpath?(path, parent_path) | |||
false | |||
end | |||
|
|||
def glob_pattern?(path) | |||
path.each_filename do |str| | |||
return true if str =~ %r!\*+|\?|\[.*\]|{.*}! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does path.include?(“*”)
not work for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to test the path component string for specific glob patterns. and regex seems better suited for it than multiple String#include?
calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashmaroli Why do we need to test each filename separately? AFAIK, the presence of *
in scope["path"]
is enough to know it's a glob pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaults:
- scope:
path: "_puppies/arrears.?"
type: "puppies"
values:
layout: arrears
is also a glob pattern to catch all kinds of files with basename arrears
, if you ask me..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't seen or used ?
before. Is that a Windows-ism?
Let's decide which glob patterns we should support and write individual tests using them so we know they work and are supported. The original PR only mentioned *
which is why I mention that one only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, for your example, I would have used "_puppets/arrears.*"
.
lib/jekyll/frontmatter_defaults.rb
Outdated
scope_path = Pathname.new(scope_path).relative_path_from site_path | ||
return true if path_is_subpath?(sanitized_path, scope_path) | ||
|
||
if glob_pattern?(rel_scope_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So instead of this, we do if scope["path"].to_s.include?("*")
. Or you can change the implementation of glob_pattern?
to just do path.to_s.include?("*")
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple unit test for glob_pattern?
would be great if you don't mind. Using my suggestion:
should "match globs" do
assert @site.frontmatter_defaults.glob_include?("content/*.pdf")
end
should "not match non-globs" do
refute @site.frontmatter_defaults.glob_include?("layouts/")
end
@parkr I don't mind adding tests at all.. but just that I find it difficult to digest your suggestion above.. /cc @pathawks for your inputs.. (Thanks in advance..) Regarding the unit test, |
Those use case seems already fine for most users, we never spoke of supporting all possible regexp patterns in path, did we?
Let's try to keep it simple here for now, and ship a quick fix. |
lib/jekyll/frontmatter_defaults.rb
Outdated
scope_path = Pathname.new(scope_path).relative_path_from site_path | ||
Jekyll.logger.debug "Globbed Scope Path:", scope_path | ||
return true if path_is_subpath?(sanitized_path, scope_path) | ||
end | ||
end | ||
|
||
path_is_subpath?(sanitized_path, rel_scope_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this an else
for the previous block (if scope["path"].to_s.include?("*")
)?
Multiple exits can get confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't make this an else
branch because if diff-ln#113
evaluates to false
even at the end of looping the globbed array, diff-ln#117
acts as a fallback..
That said, it does not make sense to me why that fallback's needed..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
docs/_docs/configuration.md
Outdated
<div class="note warning"> | ||
<h5>Globbing and Performance</h5> | ||
<p> | ||
Please note that globbing a path is a known performance-poison and is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The poison
sounds really terrifying! Can we rephrase?
Please note that front matter defaults with glob paths have known performance problems.
Windows users may notice especially high build times by adding globbing. We are tracking [in this issue](let's open an issue).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are tracking [in this issue](let's open an issue).
I believe this is an issue with Ruby for Windows itself as Ruby is not optimized for Windows.. There's not much one can do here IMO..
So.. I'll just re-phrase the "poison" bit to something more mellow..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏🏼
@jekyllbot: merge +bug |
@mmistakes If possible can you please provide the following feedback on this change using your
Thanks in advance.. |
Sure thing @ashmaroli, here's what I'm getting on Windows.
|
Right.. and the regeneration times..? |
Those are the regeneration times. It wasn't any faster regenerating the page after |
Okay buddy.. Thanks a lot..
Something's wrong somewhere!! |
Forgot to mention, I added the gem 'wdm', '>= 0.1.0' if Gem.win_platform? Without it the regen speeds were much slower for some reason. Without
|
MIND=BLOWN !! Without
|
I've never really known what adding |
Resolves #6691
Take the less expensive route unless the user configures the
scope["path"]
with a glob pattern. e.g. include"content/*.pdf"
"content/**/*"