Merge pull request #3706 from fw42/marshal_metadata

Performance: Marshal metadata
This commit is contained in:
Jordon Bedwell 2015-05-18 09:17:42 -05:00
commit 498ea4fd24
2 changed files with 20 additions and 2 deletions

View File

@ -131,7 +131,7 @@ module Jekyll
# Returns nothing. # Returns nothing.
def write_metadata def write_metadata
File.open(metadata_file, 'w') do |f| File.open(metadata_file, 'w') do |f|
f.write(metadata.to_yaml) f.write(Marshal.dump(metadata))
end end
end end
@ -158,7 +158,13 @@ module Jekyll
# Returns the read metadata. # Returns the read metadata.
def read_metadata def read_metadata
@metadata = if !disabled? && File.file?(metadata_file) @metadata = if !disabled? && File.file?(metadata_file)
SafeYAML.load(File.read(metadata_file)) content = File.read(metadata_file)
begin
Marshal.load(content)
rescue TypeError
SafeYAML.load(content)
end
else else
{} {}
end end

View File

@ -132,6 +132,18 @@ class TestRegenerator < JekyllUnitTest
assert_equal File.mtime(@path), @regenerator.metadata[@path]["mtime"] assert_equal File.mtime(@path), @regenerator.metadata[@path]["mtime"]
end end
should "read legacy yaml metadata" do
metadata_file = source_dir(".jekyll-metadata")
@regenerator = Regenerator.new(@site)
File.open(metadata_file, 'w') do |f|
f.write(@regenerator.metadata.to_yaml)
end
@regenerator = Regenerator.new(@site)
assert_equal File.mtime(@path), @regenerator.metadata[@path]["mtime"]
end
# Methods # Methods
should "be able to add a path to the metadata" do should "be able to add a path to the metadata" do