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

Optimize default front matter using File.fnmatch? #9185

Merged
merged 3 commits into from
Nov 27, 2022

Conversation

ashmaroli
Copy link
Member

@ashmaroli ashmaroli commented Nov 17, 2022

  • This is a ⚡ change.
  • I've added tests.

Summary

Instead of using Dir.glob to create a list of matching paths and testing given relative_patch against each list entry, use File.fnmatch? to directly test if given relative path matches configured scope["path"] with glob pattern sigil (*).

Notes

  • With this, there is no need for having collections_dir as part of the scope["path"]. But for backwards-compatibility, continue accepting scope["path"] with collections_dir and strip it away under the hood. TODO: Deprecate this need in a subsequent pull request.

@ashmaroli ashmaroli marked this pull request as ready for review November 17, 2022 15:06
Copy link
Member

@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using #sample (a method for randomly selecting an array element) in the tests is probably not what you want, but otherwise LGTM.

end

should "affect the appropriate items only" do
item = @staff.docs.sample
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array#sample selects a random item, so if you're expecting to always have the same item come out, then use #shift or #[].

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the intention here is to indeed test a random object in the homogeneous array during each run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every doc is the same, or the array is of size 1? I’m still confused about this. If it’s one element, it would be clearer to first assert the size, then assert its contents. If the array has >1 element that you expect to be the same, wouldn’t it be more effective to iterate over all elements and assert each element has the contents you want.

what I’m afraid of is that we’ll add a new doc or file to this collection in the fixture site and these tests will randomly fail rather than consistently fail. I think tests should be deterministic to avoid contributors chasing down confusing errors that only occur sometimes.


should "call Dir.glob block" do
assert_includes @output, "Globbed Scope Path:"
item = @staff.files.sample
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about #sample

Copy link
Member

@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ashmaroli!

@parkr
Copy link
Member

parkr commented Nov 27, 2022

Interesting Ruby 3.1 failure... couldn't compile C extensions for liquid-c.

@ashmaroli
Copy link
Member Author

Restarted it to see if it was a one-off failure..

@ashmaroli
Copy link
Member Author

This could be because of recent release Ruby 3.1.3 or maybe not.
Will merge this after investigation.

@ashmaroli
Copy link
Member Author

@parkr Can I backport this change to 4.3-stable ?

@parkr
Copy link
Member

parkr commented Nov 27, 2022

This could be because of recent release Ruby 3.1.3 or maybe not.
Will merge this after investigation.

I took a look at the repo for issues and noticed that there's a 4.1.0 release but the error looks like a 4.0.0 release. Are we able to use the latest 4.x release of liquid-c?

@parkr
Copy link
Member

parkr commented Nov 27, 2022

Can I backport this change to 4.3-stable ?

I guess, but why? Is 4.4 a big upgrade from 4.3 such that folks couldn't upgrade easily? We don't need to provide every optimization to every minor branch, but if you think folks are prevented from upgrading then go for it.

@ashmaroli
Copy link
Member Author

Are we able to use the latest 4.x release of liquid-c?

@parkr The latest release of liquid-c probably syncs with Liquid 5.x. I haven't tested though.
Regardless, my take is to lock to Ruby 3.1.2 for now. Handling in #9196

@ashmaroli
Copy link
Member Author

@jekyllbot: merge +fix

@jekyllbot jekyllbot merged commit 0cf8533 into jekyll:master Nov 27, 2022
jekyllbot added a commit that referenced this pull request Nov 27, 2022
github-actions bot pushed a commit that referenced this pull request Nov 27, 2022
Ashwin Maroli: Optimize default front matter using `File.fnmatch?` (#9185)

Merge pull request 9185
@ashmaroli ashmaroli deleted the fn_match-replace-dir-glob branch November 28, 2022 06:26
@jekyll jekyll locked and limited conversation to collaborators Nov 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants