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
205 ].compact205 ].compact
206 end206 end
207 207
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
208 def service_worker_cache_name211 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
212 if File.exist?(App.assets_manifest_path)212 if File.exist?(App.assets_manifest_path)
213 return @@service_worker_cache_name ||=213 if defined?(@@service_worker_cache_name)
214 Sprockets::Manifest214 return @@service_worker_cache_name
215 .new(nil, App.assets_manifest_path)215 end
216 .files216
217 .values217 digest = Sprockets::Manifest
218 .sort_by {|file| file["mtime"]}218 .new(nil, App.assets_manifest_path)
219 .reverse219 .files
220 .first["digest"]220 .values
221 .map {|file| file["digest"]}
222 .join
223
224 return @@service_worker_cache_name ||= Digest::MD5.hexdigest(digest)
221 else225 else
222 last_modified_file = App.sprockets226 paths = App.sprockets
223 .each_file227 .each_file
224 .to_a228 .to_a
225 .reject {|file| file.start_with?(App.docs_path)}229 .reject {|file| file.start_with?(App.docs_path)}
226 .max_by {|file| File.mtime(file)}
227 230
228 return App.sprockets.pack_base64digest(App.sprockets.file_digest(last_modified_file))231 return App.sprockets.pack_hexdigest(App.sprockets.files_digest(paths))
229 end232 end
230 end233 end
231 234
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