mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 01:03:41 +08:00
FIX: Automatically recover from bad sprockets cache in development (#8364)
We were having issues in development mode where the JS code had errors due to a bad cache. When starting a server in development mode in bin/unicorn we now get the git sha of the discourse HEAD and get a git sha of all plugins, and store them in a file. If the sha has changed then we delete tmp/cache to refresh the assets cache.
This commit is contained in:
24
bin/unicorn
24
bin/unicorn
@ -4,12 +4,35 @@
|
|||||||
require 'pathname'
|
require 'pathname'
|
||||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
||||||
Pathname.new(__FILE__).realpath)
|
Pathname.new(__FILE__).realpath)
|
||||||
|
RAILS_ROOT = File.expand_path("../../", Pathname.new(__FILE__).realpath)
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
|
require 'digest'
|
||||||
|
|
||||||
dev_mode = false
|
dev_mode = false
|
||||||
|
|
||||||
|
def ensure_cache_clean!
|
||||||
|
all_plugin_directories = Pathname.new(RAILS_ROOT + '/plugins').children.select(&:directory?)
|
||||||
|
core_git_sha = `git rev-parse HEAD`
|
||||||
|
sorted_plugin_shas = all_plugin_directories.map do |plugin_dir|
|
||||||
|
"#{plugin_dir}:" + `git ls-files -s #{plugin_dir} | git hash-object --stdin`
|
||||||
|
end.sort
|
||||||
|
supersha_hash = Digest::SHA1.hexdigest((sorted_plugin_shas + [core_git_sha]).join('|'))
|
||||||
|
hash_file = "#{RAILS_ROOT}/tmp/plugin-hash"
|
||||||
|
|
||||||
|
old_hash = File.exists?(hash_file) ? File.read(hash_file) : nil
|
||||||
|
|
||||||
|
if old_hash && old_hash != supersha_hash
|
||||||
|
puts "WARNING: It looks like your discourse plugins or core version have recently changed."
|
||||||
|
puts "The tmp/cache directory will be wiped to avoid development issues."
|
||||||
|
`rm -rf #{RAILS_ROOT}/tmp/cache`
|
||||||
|
puts
|
||||||
|
end
|
||||||
|
|
||||||
|
File.write(hash_file, supersha_hash)
|
||||||
|
end
|
||||||
|
|
||||||
# in development do some fussing around, to automate config
|
# in development do some fussing around, to automate config
|
||||||
if !ARGV.include?("-E") &&
|
if !ARGV.include?("-E") &&
|
||||||
!ARGV.include?("--env") &&
|
!ARGV.include?("--env") &&
|
||||||
@ -38,6 +61,7 @@ if !ARGV.include?("-E") &&
|
|||||||
|
|
||||||
ENV["UNICORN_SIDEKIQS"] ||= "1"
|
ENV["UNICORN_SIDEKIQS"] ||= "1"
|
||||||
|
|
||||||
|
ensure_cache_clean!
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV.include?("--help")
|
if ARGV.include?("--help")
|
||||||
|
@ -183,29 +183,8 @@ module Discourse
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.activate_plugins!
|
def self.activate_plugins!
|
||||||
all_plugins = Plugin::Instance.find_all("#{Rails.root}/plugins")
|
|
||||||
|
|
||||||
if Rails.env.development?
|
|
||||||
plugin_hash = Digest::SHA1.hexdigest(all_plugins.map { |p| p.path }.sort.join('|'))
|
|
||||||
hash_file = "#{Rails.root}/tmp/plugin-hash"
|
|
||||||
|
|
||||||
old_hash = begin
|
|
||||||
File.read(hash_file)
|
|
||||||
rescue Errno::ENOENT
|
|
||||||
end
|
|
||||||
|
|
||||||
if old_hash && old_hash != plugin_hash
|
|
||||||
puts "WARNING: It looks like your discourse plugins have recently changed."
|
|
||||||
puts "It is highly recommended to remove your `tmp` directory, otherwise"
|
|
||||||
puts "plugins might not work."
|
|
||||||
puts
|
|
||||||
else
|
|
||||||
File.write(hash_file, plugin_hash)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@plugins = []
|
@plugins = []
|
||||||
all_plugins.each do |p|
|
Plugin::Instance.find_all("#{Rails.root}/plugins").each do |p|
|
||||||
v = p.metadata.required_version || Discourse::VERSION::STRING
|
v = p.metadata.required_version || Discourse::VERSION::STRING
|
||||||
if Discourse.has_needed_version?(Discourse::VERSION::STRING, v)
|
if Discourse.has_needed_version?(Discourse::VERSION::STRING, v)
|
||||||
p.activate!
|
p.activate!
|
||||||
|
Reference in New Issue
Block a user