[devdocsgjs/main: 653/1867] Better cache name creation




commit 5dc1437631ae662b80a0aae18e7c59391a46bcaf
Author: Jasper van Merle <jaspervmerle gmail com>
Date:   Wed Jul 10 22:38:33 2019 +0200

    Better cache name creation

 lib/app.rb             | 31 +++++++++++++++++--------------
 log/newrelic_agent.log | 14 ++++++++++++++
 2 files changed, 31 insertions(+), 14 deletions(-)
---
diff --git a/lib/app.rb b/lib/app.rb
index a0063e49..d193fa6a 100644
--- a/lib/app.rb
+++ b/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
 
diff --git a/log/newrelic_agent.log b/log/newrelic_agent.log
new file mode 100644
index 00000000..528fd5ff
--- /dev/null
+++ b/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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]