History

Better cache name creation

Jasper van Merle committed 7 years ago

Commit 5dc14371 parent 2bbbc662 files · +31 −14Browse files

Unified · Split

2 files
  1. lib/app.rb +17 −14
  2. log/newrelic_agent.log +14 −0
lib/app.rb+17−14
@@ -205,27 +205,30 @@ class App < Sinatra::Application · 204 unmodified lines
205205 ].compact
206206 end
207207
208+ # Returns a cache name for the service worker to use which changes if any of the assets changes
209+ # When a manifest exist, this name is only created once based on the asset manifest because it never changes without a server restart
210+ # 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
208211 def service_worker_cache_name
209− # Returns the digest of the last modified asset
210− # When a manifest exist, this digest is only calculated once based on the asset manifest because it never changes without a server restart
211− # 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
212212 if File.exist?(App.assets_manifest_path)
213− return @@service_worker_cache_name ||=
214− Sprockets::Manifest
215− .new(nil, App.assets_manifest_path)
216− .files
217− .values
218− .sort_by {|file| file["mtime"]}
219− .reverse
220− .first["digest"]
213+ if defined?(@@service_worker_cache_name)
214+ return @@service_worker_cache_name
215+ end
216+
217+ digest = Sprockets::Manifest
218+ .new(nil, App.assets_manifest_path)
219+ .files
220+ .values
221+ .map {|file| file["digest"]}
222+ .join
223+
224+ return @@service_worker_cache_name ||= Digest::MD5.hexdigest(digest)
221225 else
222− last_modified_file = App.sprockets
226+ paths = App.sprockets
223227 .each_file
224228 .to_a
225229 .reject {|file| file.start_with?(App.docs_path)}
226− .max_by {|file| File.mtime(file)}
227230
228− return App.sprockets.pack_base64digest(App.sprockets.file_digest(last_modified_file))
231+ return App.sprockets.pack_hexdigest(App.sprockets.files_digest(paths))
229232 end
230233 end
231234
log/newrelic_agent.log+14−0
@@ -0,0 +1,14 @@
1+# Logfile created on 2019-07-10 22:09:26 +0200 by logger.rb/66358
2+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Starting the New Relic agent version 5.7.0.350 in "production" environment.
3+[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.
4+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Reading configuration from newrelic.yml (/home/jasper/Projects/devdocs)
5+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : No application name configured.
6+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : The Agent cannot start without at least one. Please check your
7+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : newrelic.yml and ensure that it is valid and has at least one
8+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : value set for app_name in the production
9+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : environment.
10+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Sinatra instrumentation
11+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Net instrumentation
12+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing deferred Rack::Builder instrumentation
13+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Rack::Builder middleware instrumentation
14+[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Finished instrumentation

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t