Ver Fonte

Better cache name creation

Jasper van Merle há 6 anos atrás
pai
commit
5dc1437631
2 ficheiros alterados com 31 adições e 14 exclusões
  1. 17 14
      lib/app.rb
  2. 14 0
      log/newrelic_agent.log

+ 17 - 14
lib/app.rb

@@ -205,27 +205,30 @@ class App < Sinatra::Application
       ].compact
     end
 
+    # Returns a cache name for the service worker to use which changes if any of the assets changes
+    # When a manifest exist, this name is only created once based on the asset manifest because it never changes without a server restart
+    # If a manifest does not exist, it is created every time this method is called because the assets can change while the server is running
     def service_worker_cache_name
-      # Returns the digest of the last modified asset
-      # When a manifest exist, this digest is only calculated once based on the asset manifest because it never changes without a server restart
-      # If a manifest does not exist, it is calculated every time this method is called because the assets can change while the server is running
       if File.exist?(App.assets_manifest_path)
-        return @@service_worker_cache_name ||=
-          Sprockets::Manifest
-            .new(nil, App.assets_manifest_path)
-            .files
-            .values
-            .sort_by {|file| file["mtime"]}
-            .reverse
-            .first["digest"]
+        if defined?(@@service_worker_cache_name)
+          return @@service_worker_cache_name
+        end
+
+        digest = Sprockets::Manifest
+          .new(nil, App.assets_manifest_path)
+          .files
+          .values
+          .map {|file| file["digest"]}
+          .join
+
+        return @@service_worker_cache_name ||= Digest::MD5.hexdigest(digest)
       else
-        last_modified_file = App.sprockets
+        paths = App.sprockets
           .each_file
           .to_a
           .reject {|file| file.start_with?(App.docs_path)}
-          .max_by {|file| File.mtime(file)}
 
-        return App.sprockets.pack_base64digest(App.sprockets.file_digest(last_modified_file))
+        return App.sprockets.pack_hexdigest(App.sprockets.files_digest(paths))
       end
     end
 

+ 14 - 0
log/newrelic_agent.log

@@ -0,0 +1,14 @@
+# Logfile created on 2019-07-10 22:09:26 +0200 by logger.rb/66358
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Starting the New Relic agent version 5.7.0.350 in "production" environment.
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : To prevent agent startup add a NEW_RELIC_AGENT_ENABLED=false environment variable or modify the "production" section of your newrelic.yml.
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Reading configuration from newrelic.yml (/home/jasper/Projects/devdocs)
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : No application name configured.
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : The Agent cannot start without at least one. Please check your 
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : newrelic.yml and ensure that it is valid and has at least one 
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : value set for app_name in the production 
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : environment.
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Sinatra instrumentation
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Net instrumentation
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing deferred Rack::Builder instrumentation
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Rack::Builder middleware instrumentation
+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Finished instrumentation