Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Turn off asset expiration handling by default.

  • Loading branch information...
commit 12f1e0375925f701766b78207eb6c1ca25722b08 1 parent 0e72a02
@ndbroadbent authored
Showing with 18 additions and 9 deletions.
  1. +3 −0  README.md
  2. +15 −9 lib/turbo-sprockets/tasks/assets.rake
View
3  README.md
@@ -35,6 +35,9 @@ Enjoy your lightning fast deploys!
`turbo-sprockets-rails3` provides a Rake task called `assets:clean_expired`. You can run this task after `assets:precompile` to remove outdated assets.
+If you use this rake task, you must set `config.assets.handle_expiration` to true in `config/environments/production.rb`. This makes sure that asset modification times
+are updated properly before `assets:precompile`, so that the `clean_expired` task knows which assets are safe to remove.
+
An asset will be deleted if it is no longer referenced by `manifest.yml`, and hasn't been actively deployed for more than a day (default).
You can configure the expiry time by setting `config.assets.expire_after` in `config/environments/production.rb`.
View
24 lib/turbo-sprockets/tasks/assets.rake
@@ -67,19 +67,25 @@ namespace :assets do
config.assets.digest = digest unless digest.nil?
config.assets.digests ||= {}
config.assets.source_digests ||= {}
+ config.assets.handle_expiration = false if config.assets.handle_expiration.nil?
env = Rails.application.assets
target = File.join(::Rails.public_path, config.assets.prefix)
- # Before first compile, set the mtime of all current assets to current time.
- # This time reflects the last time the assets were being used.
- if digest.nil?
- ::Rails.logger.debug "Updating mtimes for current assets..."
- paths = known_assets.map { |asset| File.join(target, asset) }
- paths.each_slice(100) 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}`
+ # This takes a long time to run if you aren't cleaning expired assets.
+ # You must call the assets:clean_expired rake task regularly if this is
+ # enabled
+ if config.assets.handle_expiration
+ # Before first compile, set the mtime of all current assets to current time.
+ # This time reflects the last time the assets were being used.
+ if digest.nil?
+ ::Rails.logger.debug "Updating mtimes for current assets..."
+ paths = known_assets.map { |asset| File.join(target, asset) }
+ paths.each_slice(100) 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
end
Please sign in to comment.
Something went wrong with that request. Please try again.