ææãä»äºã§Railsã®config.load_defaults
ã®ãã¼ã¸ã§ã³ãä¸ãã¦ããä½æ¥ããã¦ãã¾ããå
·ä½çã«ã¯ä¸ãããã¼ã¸ã§ã³ã«å«ã¾ããããããã®è¨å®ã®æå³ãç解ãã¦ãå½±é¿ç¯å²ãææ¡ããããã§ä¸ã¤ã¥ã¤Pull Requestãä½ãããã«ãã¦ãã¾ããå®éã«ãã£ã¦ã¿ãææ³ã¨ãã¦ã¯ãããã¯ãªããªãé£æ度ãé«ããã¡ãã¨å½±é¿ç¯å²ãç解ããããã§å®æ½ã§ãã¦ããããã¸ã§ã¯ãã¯å°ãªãã®ã§ã¯ãªããï¼ã¨æãã¾ãããããã§ãããããconfig.load_defaults
ã®ãã¼ã¸ã§ã³ãä¸ãã人ã®å½¹ã«ç«ã¤ããã«ããã°ã¨ã³ããªãæ¸ãã¦ã¿ã次第ã§ãã
ä»æ¥ã¯config.load_defaults 7.0
ã«å«ã¾ããconfig.active_support.hash_digest_class = OpenSSL::Digest::SHA256
ãåãä¸ãã¾ãã
- 対象ã¨ãªãã³ããã: Change the default digest for new apps to SHA256 · rails/rails@ba9207f
- é¢é£URL: Upgrading Ruby on Rails â Ruby on Rails Guides
config.active_support.hash_digest_class = OpenSSL::Digest::SHA256
ã¯ã主ã«ãã£ãã·ã¥ã®ãã¼ã«å¯¾ãã¦å©ç¨ããããã·ã¥é¢æ°ãSHA256ã«ãããã¨ãããã®ã§ãããã¨ãã¨ã®ããã·ã¥é¢æ°ã¯MD5ã§ããããRails5.2ã§ããã©ã«ãSHA1ã«å¤æ´ããã7.0ã§ã¯SHA256ã«ãªãã¾ããã
ä»åã®ããã·ã¥åã®å¯¾è±¡ã¯ãã£ãã·ã¥ãã¼ã§ãããããSHA1ãèå¼±ãªã®ãåé¡ã¨ããããã§ã¯ããã¾ãããRailså ¨ä½ã¨ãã¦SHA256ã使ãããã«ããã¨ã»ãã¥ãªãã£æ¨æºãæºããã¦ãããã©ããã®ãã§ãã¯ã楽ã«ãªããã¨ããçç±ã§å¤æ´ãåæ ãããããã§ãã
Railså ã§é¢é£ã®ããé¨å
Railsã®ã³ã¼ããè¦ãéããå©ç¨ãã¦ããç®æã¯æ¬¡ã®4ç®æã§ãã
- ãã©ã°ã¡ã³ããã£ãã·ã¥ã®ãã¼ã決ããç®æ(ãã³ãã¬ã¼ãé¨å)
- cache ã¡ã½ãã ã®template tree digestãç®åºããããã«ä½¿ããã¦ãã
- ãã©ã°ã¡ã³ããã£ãã·ã¥ã®å¼æ°ã§
cache(User.all) do
ã®ããã«ActiveRecord::Relationã使ã£ãã¨ãã®ãã¼ã決ããç®æ(idé¨å)- cache ã¡ã½ãã ã®idã®é¨åãç®åºããããã«ä½¿ããã¦ãã
- å¼·ãETagã®çæ
- é·ããã£ãã·ã¥ãã¼ã縮ãã
åºæ¬çã«ãããã®ãã£ãã·ã¥ãå©ç¨ãã¦ããªããã°åé¡ãªãè¨å®ãå¤æ´ã§ãããã§ãã
å¤æ´ãå½±é¿ããç®æã®ç¢ºèªæ¹æ³
ãã£ãã·ã¥ãå©ç¨ãã¦ãããã©ããã¯ååãªãã¹ãã«ãã¬ãã¸ãããã°ã次ã®ãããªã¢ã³ãã¼ãããã§ç¢ºèªã§ãã¾ã*1ãä¸è¨ã®ã³ã¼ãã§ã¯ãActiveSupport::Digest.hexdigest
ãå®è¡ããå ´æããã°ã«åºåãã¦ãã¾ããããCIã§ä¸¦åå®è¡ããã¦ããããã§ããã°ãé©å®ãã°ããã¼ã¸ãã¦ç¢ºèªãã¦ãã ããã
# config/application.rb or config/initializers/something.rb module MonkeyPatch def monkeypatch_logger @monkeypatch_logger ||= Logger.new(Rails.root.join('log/monkeypatch.log')) end def hexdigest(*) monkeypatch_logger.debug("ActiveSupport::Digest.hexdigest is called from: #{caller(2, 1).first}") super end end class ActiveSupport::Digest class << self prepend MonkeyPatch end end
ãã¹ãå®è¡åã«ã次ã®ããã«ãã£ãã·ã¥ãæå¹ãã¤ãã£ãã·ã¥ã¹ãã¢ãNullStoreã«è¨å®ãã¦ããã®ãå¿ããªãããã«ãã¾ãããã
# config/environments/test.rb config.action_controller.perform_caching = true config.cache_store = :null_store
ããå©ç¨ãã¦ããç®æããã£ãããè¨å®å¤æ´ã«ãããããã¤å¾ã«é¢é£ãããã£ãã·ã¥ããã¹ã¦invalidã«ãªãã¾ããè² è·ãä¸ãããã¨ãäºæ³ãããã®ã§ãä¸æçã«ã¢ããªã±ã¼ã·ã§ã³ãµã¼ããDBãµã¼ããå¢å¼·ããå¿ è¦ãããããã§ãã
*1:ãé·ããã£ãã·ã¥ãã¼ã縮ãããã®ç®æãé¤ã