From 3043f410bc5db0510d2441d8fe6e1eef9264cbdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beausoleil?= Date: Mon, 22 Aug 2016 20:09:16 +0000 Subject: [PATCH] Remove chance of inconsistent UI by not caching --- app.rb | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/app.rb b/app.rb index 496d5de..8534525 100644 --- a/app.rb +++ b/app.rb @@ -30,10 +30,6 @@ def call(env) configure :development do set :port, 4321 - - def set_last_modified(user_id) - # NOP, no last_modified or cache_control in development - end end configure :production do @@ -49,11 +45,6 @@ def set_last_modified(user_id) # Use threaded async reporter config.use_thread end unless ENV["ROLLBAR_ACCESS_TOKEN"].to_s.empty? - - def set_last_modified(user_id) - last_modified DB[table_name_from_user_id(user_id)].max(:start_at) - cache_control :private, max_age: 60 - end end configure do @@ -73,12 +64,19 @@ def set_last_modified(user_id) end end +before do + unless request.path_info == "/" then + # 99% of pages must not be cached: only the home page should be + cache_control :no_cache, :no_store, :must_revalidate, max_age: 0 unless @stage == "development" + end +end + def table_name_from_user_id(user_id) "events_#{user_id}".tr("-", "_").to_sym end get "/" do - cache_control :public, max_age: 600 if @stage == "production" + cache_control :public, max_age: 3600 if @stage == "production" erb :home, layout: :layout end @@ -103,8 +101,6 @@ def table_name_from_user_id(user_id) end get %r{\A/me/#{UUID_RE}\z} do |user_id| - set_last_modified user_id - @last5 = DB[table_name_from_user_id(user_id)]. select( :event_id, @@ -148,8 +144,6 @@ def table_name_from_user_id(user_id) end get %r{\A/me/#{UUID_RE}/analytics} do |user_id| - set_last_modified user_id - avg_hours_slept_per_weekday_ds = DB[<<-EOSQL, table_name: table_name_from_user_id(user_id)] SELECT dow @@ -201,7 +195,6 @@ def table_name_from_user_id(user_id) @user_id = user_id @app = :settings - cache_control :private, :must_revalidate, max_age: 60 if @stage == "production" erb :settings end @@ -214,7 +207,6 @@ def table_name_from_user_id(user_id) local_end_at: tz.utc_to_local(@event.fetch(:end_at))) @app = :app - cache_control :no_cache, :no_store, :must_revalidate if @stage == "production" erb :edit end