Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use integer time instead of Time objects

Parsing times is slow. This takes up a lot of time when loading large
manifests. Using integer timestamps should also work better across
multiple platforms. We also completley avoid timezone math.
  • Loading branch information...
commit 26b512cdaa79008b30d35e986b1a4555236717d6 1 parent 596b8a1
twinturbo authored
View
8 lib/rake-pipeline/dynamic_file_task.rb
@@ -76,7 +76,7 @@ def needed?
# If any of this task's dynamic dependencies have changed,
# this file task is needed
last_manifest_entry.deps.each do |dep, time|
- return true if File.mtime(dep) > time
+ return true if File.mtime(dep).to_i > time
end
# Otherwise, it's not needed
@@ -142,7 +142,7 @@ def invoke_prerequisites(task_args, invocation_chain)
entry = Rake::Pipeline::ManifestEntry.new
dynamics.each do |dynamic|
- entry.deps.merge!(dynamic => mtime_or_now(dynamic))
+ entry.deps.merge!(dynamic => mtime_or_now(dynamic).to_i)
end
self.manifest_entry = entry
@@ -153,7 +153,7 @@ def invoke_prerequisites(task_args, invocation_chain)
def invoke_with_call_chain(*)
super
- manifest_entry.mtime = mtime_or_now(name)
+ manifest_entry.mtime = mtime_or_now(name).to_i
end
private
@@ -180,7 +180,7 @@ def dynamic_prerequisites_from_manifest
# list of dependencies in the manifest, which
# come from the return value of the dynamic block
# in a previous run.
- if File.exist?(name) && mtime == File.mtime(name)
+ if File.exist?(name) && mtime == File.mtime(name).to_i
return last_manifest_entry.deps.map { |k,v| k }
end
end
View
4 lib/rake-pipeline/manifest_entry.rb
@@ -6,10 +6,10 @@ class ManifestEntry
def self.from_hash(hash)
entry = new
- entry.mtime = DateTime.parse(hash["mtime"]).to_time
+ entry.mtime = hash["mtime"]
hash["deps"].each do |dep, time_string|
- entry.deps[dep] = DateTime.parse(time_string).to_time
+ entry.deps[dep] = time_string
end
entry
View
13 spec/dynamic_file_task_spec.rb
@@ -20,11 +20,6 @@ def define_task(deps, klass=Rake::Pipeline::DynamicFileTask, &task_proc)
let(:task) { define_task('output') }
- before do
- # Make sure date conversions happen in UTC, not local time
- ENV['TZ'] = 'UTC'
- end
-
after do
# Clean out all defined tasks after each test runs
Rake.application = Rake::Application.new
@@ -57,13 +52,13 @@ def define_task(deps, klass=Rake::Pipeline::DynamicFileTask, &task_proc)
it "adds dynamic dependencies to its manifest entry" do
dynamic_task.invoke
dynamic_task.manifest_entry.deps.should == {
- 'dynamic' => File.mtime('dynamic')
+ 'dynamic' => File.mtime('dynamic').to_i
}
end
it "adds the current task's mtime to its manifest entry" do
dynamic_task.invoke
- dynamic_task.manifest_entry.mtime.should == File.mtime('output')
+ dynamic_task.manifest_entry.mtime.should == File.mtime('output').to_i
end
it "raises an error when there is no manifest" do
@@ -109,9 +104,9 @@ def make_file(name, mtime=nil)
manifest_entry = Rake::Pipeline::ManifestEntry.from_hash({
"deps" => {
- "blinky" => "2000-01-01 00:00:00 +0000"
+ "blinky" => time.to_i
},
- "mtime" => "2000-01-01 00:00:00 +0000"
+ "mtime" => time.to_i
})
task.dynamic { %w[] }
View
23 spec/manifest_entry_spec.rb
@@ -1,18 +1,13 @@
require 'spec_helper'
describe Rake::Pipeline::ManifestEntry do
- before do
- # ensure all our date/time conversions happen in UTC.
- ENV['TZ'] = 'UTC'
- end
-
let(:hash) do
{
"deps" => {
- "file.h" => "2001-01-01 00:00:00 +0000",
- "other.h" => "2001-01-01 00:00:00 +0000"
+ "file.h" => 100,
+ "other.h" => 100
},
- "mtime" => "2000-01-01 00:00:00 +0000"
+ "mtime" => 200
}
end
@@ -25,13 +20,13 @@
subject.should be_kind_of described_class
end
- it "parses mtime value into a Time" do
- subject.mtime.should == Time.utc(2000)
+ it "should leave mtimes have integers" do
+ subject.mtime.should == 200
end
it "parses each time from the deps value into a Time" do
subject.deps.each do |file, mtime|
- mtime.should == Time.utc(2001)
+ mtime.should == 100
end
end
end
@@ -40,10 +35,10 @@
it "returns a hash representation of the entry for converting to json" do
subject.as_json.should == {
:deps => {
- "file.h" => Time.utc(2001),
- "other.h" => Time.utc(2001),
+ "file.h" => 100,
+ "other.h" => 100
},
- :mtime => Time.utc(2000)
+ :mtime => 200
}
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.