Skip to content

Commit

Permalink
Remove chance of inconsistent UI by not caching
Browse files Browse the repository at this point in the history
  • Loading branch information
francois committed Aug 22, 2016
1 parent bfcd1d3 commit 3043f41
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 3043f41

Please sign in to comment.