cache full pages for logged-out visitors without tag filters

This commit is contained in:
Peter Bhat Harkins 2018-05-10 10:09:47 -05:00
parent a59cf79956
commit f278565e09
10 changed files with 30 additions and 7 deletions

18
Gemfile
View File

@ -1,34 +1,38 @@
source "https://rubygems.org"
gem "json"
gem "rails", "~> 5.1"
gem "unicorn"
gem "mysql2", "~> 0.3.20"
# uncomment to use PostgreSQL
# gem "pg"
# rails
gem 'scenic'
gem 'scenic-mysql'
gem "activerecord-typedstore"
gem "uglifier", ">= 1.3.0"
gem "jquery-rails", "~> 4.3"
# js
gem "dynamic_form"
gem "jquery-rails", "~> 4.3"
gem "json"
gem "uglifier", ">= 1.3.0"
# deployment
gem "actionpack-page_caching"
gem "exception_notification"
gem "unicorn"
# security
gem "bcrypt", "~> 3.1.2"
gem "rotp"
gem "rqrcode"
# parsing
gem "nokogiri", ">= 1.7.2"
gem "htmlentities"
gem "commonmarker", "~> 0.14"
gem "activerecord-typedstore"
# for twitter-posting bot
gem "oauth"

View File

@ -18,6 +18,8 @@ GEM
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionpack-page_caching (1.1.0)
actionpack (>= 4.0.0, < 6)
actionview (5.1.5)
activesupport (= 5.1.5)
builder (~> 3.1)
@ -194,6 +196,7 @@ PLATFORMS
ruby
DEPENDENCIES
actionpack-page_caching
activerecord-typedstore
bcrypt (~> 3.1.2)
bullet

View File

@ -5,8 +5,11 @@ class ApplicationController < ActionController::Base
TRAFFIC_DECREMENTER = 0.50
# match this in your nginx config for bypassing the file cache
TAG_FILTER_COOKIE = :tag_filters
CACHE_PAGE = proc { @user.blank? && cookies[TAG_FILTER_COOKIE].blank? }
def authenticate_user
# eagerly evaluate, in case this triggers an IpSpoofAttackError
request.remote_ip

View File

@ -1,6 +1,8 @@
class CommentsController < ApplicationController
COMMENTS_PER_PAGE = 20
caches_page :index, :threads, if: CACHE_PAGE
# for rss feeds, load the user's tag filters if a token is passed
before_action :find_user_from_rss_token, :only => [:index]
before_action :require_logged_in_user_or_400,

View File

@ -1,4 +1,6 @@
class HomeController < ApplicationController
caches_page :about, :chat, :index, :newest, :newest_by_user, :recent, :top, if: CACHE_PAGE
# for rss feeds, load the user's tag filters if a token is passed
before_action :find_user_from_rss_token, :only => [:index, :newest, :saved]
before_action { @page = page }

View File

@ -1,4 +1,6 @@
class StoriesController < ApplicationController
caches_page :show, if: CACHE_PAGE
before_action :require_logged_in_user_or_400,
:only => [:upvote, :downvote, :unvote, :hide, :unhide, :preview, :save, :unsave]
before_action :require_logged_in_user,

View File

@ -75,6 +75,8 @@ Lobsters::Application.configure do
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.action_controller.page_cache_directory = "#{Rails.root}/public/cache"
end
%w{render_template render_partial render_collection}.each do |event|

View File

@ -1,5 +1,6 @@
# Be sure to restart your server when you modify this file.
# match this in your nginx config for bypassing the file cache
Lobsters::Application.config.session_store :cookie_store,
key: 'lobster_trap',
expire_after: 1.month

0
public/cache/.gitkeep vendored Normal file
View File

4
script/expire_page_cache Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
find /srv/lobste.rs/http/public/cache/ -type f -not -mmin 2 -not -name ".gitkeep" -delete
find /srv/lobste.rs/http/public/cache/ -type d -empty -delete