Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Speed up touching, make shell escaping more robust. #48

Merged
merged 1 commit into from

2 participants

@oggy

1.

Shellwords is part of the ruby stdlib, and built for proper shell escaping.

2.

The touch command can receive multiple files, and can even ignore nonexistent files with the POSIX-compliant -c option. Doing 1000 files per invocation dramatically sped up this phase of precompilation for me. On an app with just under 7k files under public/assets:

Before:

$ bundle exec rake RAILS_ENV=development RAILS_GROUPS=assets assets:precompile
touching (nil): 88.8947s
compiling (nil): 70.7533s
touching (false): 0.0000s
generating (false): 6.5764s

After:

$ bundle exec rake RAILS_ENV=development RAILS_GROUPS=assets assets:precompile
touching (nil): 0.9903s
compiling (nil): 68.2418s
touching (false): 0.0000s
generating (false): 6.4802s

@ndbroadbent ndbroadbent merged commit 8bc8007 into from
@ndbroadbent
Owner

Awesome, thanks!! I've released 0.3.5 with your change.

@oggy oggy deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 6, 2013
  1. @oggy
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 7 deletions.
  1. +6 −7 lib/turbo-sprockets/tasks/assets.rake
View
13 lib/turbo-sprockets/tasks/assets.rake
@@ -1,4 +1,5 @@
require "fileutils"
+require 'shellwords'
# Clear all assets tasks from sprockets railtie,
# but preserve any extra actions added via 'enhance'
@@ -74,13 +75,11 @@ namespace :assets do
# This time reflects the last time the assets were being used.
if digest.nil?
::Rails.logger.debug "Updating mtimes for current assets..."
- known_assets.each do |asset|
- full_path = File.join(target, asset)
- if File.exist?(full_path)
- # File.utime raises 'Operation not permitted' unless user is owner of file.
- # Non-owners have permission to update mtime to the current time using 'touch'.
- `touch "#{full_path}"`
- end
+ paths = known_assets.map { |asset| File.join(target, asset) }
+ paths.each_slice(1000) do |slice|
+ # File.utime raises 'Operation not permitted' unless user is owner of file.
+ # Non-owners have permission to update mtime to the current time using 'touch'.
+ `touch -c #{slice.shelljoin}`
end
end
Something went wrong with that request. Please try again.