caching
This commit is contained in:
parent
d587ed58b7
commit
1154da1fd1
@ -1 +1 @@
|
||||
2.5.0
|
||||
2.4.3
|
@ -1,4 +1,4 @@
|
||||
FROM phusion/passenger-ruby25:latest
|
||||
FROM phusion/passenger-ruby24:latest
|
||||
|
||||
# Use baseimage-docker's init process.
|
||||
CMD ["/sbin/my_init"]
|
||||
|
6
Gemfile
6
Gemfile
@ -5,7 +5,9 @@ gem 'pg', '~> 0.21.0'
|
||||
|
||||
gem 'webpacker', '3.4.1'
|
||||
gem 'bootsnap', '>= 1.1.0', require: false
|
||||
gem 'jbuilder', '~> 2.7'
|
||||
|
||||
#gem 'jbuilder', '~> 2.7'
|
||||
gem 'jbuilder', git: 'https://github.com/rails/jbuilder', branch: 'master'
|
||||
|
||||
gem 'oj', '~> 3.5.0'
|
||||
|
||||
@ -13,6 +15,8 @@ gem 'kaminari', '~> 1.1.1'
|
||||
gem 'unitwise', '~> 2.2.0'
|
||||
gem 'redcarpet', '~> 3.4.0'
|
||||
|
||||
gem 'dalli', '~> 2.7.6'
|
||||
|
||||
# Use ActiveModel has_secure_password
|
||||
gem 'bcrypt', '~> 3.1.11'
|
||||
|
||||
|
16
Gemfile.lock
16
Gemfile.lock
@ -1,3 +1,12 @@
|
||||
GIT
|
||||
remote: https://github.com/rails/jbuilder
|
||||
revision: a0dc0bd42737aaef3dd622d8338a816aed03c8ff
|
||||
branch: master
|
||||
specs:
|
||||
jbuilder (2.7.0)
|
||||
activesupport (>= 4.2.0)
|
||||
multi_json (>= 1.2)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
@ -50,6 +59,7 @@ GEM
|
||||
coderay (1.1.2)
|
||||
concurrent-ruby (1.0.5)
|
||||
crass (1.0.3)
|
||||
dalli (2.7.7)
|
||||
database_cleaner (1.6.2)
|
||||
diff-lcs (1.3)
|
||||
erubi (1.7.1)
|
||||
@ -78,9 +88,6 @@ GEM
|
||||
rspec (>= 2.99.0, < 4.0)
|
||||
i18n (1.0.0)
|
||||
concurrent-ruby (~> 1.0)
|
||||
jbuilder (2.7.0)
|
||||
activesupport (>= 4.2.0)
|
||||
multi_json (>= 1.2)
|
||||
kaminari (1.1.1)
|
||||
activesupport (>= 4.1.0)
|
||||
kaminari-actionview (= 1.1.1)
|
||||
@ -224,11 +231,12 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
bcrypt (~> 3.1.11)
|
||||
bootsnap (>= 1.1.0)
|
||||
dalli (~> 2.7.6)
|
||||
database_cleaner (~> 1.6.2)
|
||||
factory_bot_rails (~> 4.8.2)
|
||||
guard (~> 2.14.0)
|
||||
guard-rspec
|
||||
jbuilder (~> 2.7)
|
||||
jbuilder!
|
||||
kaminari (~> 1.1.1)
|
||||
oj (~> 3.5.0)
|
||||
pg (~> 0.21.0)
|
||||
|
@ -1,7 +1,7 @@
|
||||
class RecipeIngredient < ApplicationRecord
|
||||
|
||||
belongs_to :ingredient, optional: true
|
||||
belongs_to :recipe, inverse_of: :recipe_ingredients
|
||||
belongs_to :recipe, inverse_of: :recipe_ingredients, touch: true
|
||||
|
||||
validates :sort_order, presence: true
|
||||
|
||||
|
@ -1,17 +1,20 @@
|
||||
|
||||
json.extract! @ingredients, :total_count, :total_pages, :current_page
|
||||
json.page_size @ingredients.limit_value
|
||||
json.cache_root! [Ingredient.all, @ingredients] do
|
||||
|
||||
json.ingredients @ingredients do |i|
|
||||
json.extract! i, :id, :name, :ndbn, :kcal
|
||||
json.usda i.ndbn.present?
|
||||
json.extract! @ingredients, :total_count, :total_pages, :current_page
|
||||
json.page_size @ingredients.limit_value
|
||||
|
||||
json.ingredients @ingredients do |i|
|
||||
json.extract! i, :id, :name, :ndbn, :kcal
|
||||
json.usda i.ndbn.present?
|
||||
|
||||
if i.density.present?
|
||||
value = UnitConversion::parse(i.density)
|
||||
json.density value.convert('oz/cup').change_formatter(UnitConversion::DecimalFormatter.new).pretty_value
|
||||
else
|
||||
json.density nil
|
||||
end
|
||||
|
||||
if i.density.present?
|
||||
value = UnitConversion::parse(i.density)
|
||||
json.density value.convert('oz/cup').change_formatter(UnitConversion::DecimalFormatter.new).pretty_value
|
||||
else
|
||||
json.density nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -1,10 +1,13 @@
|
||||
|
||||
json.extract! @recipes, :total_count, :total_pages, :current_page
|
||||
json.page_size @recipes.limit_value
|
||||
json.cache_root! [Recipe.all, @recipes] do
|
||||
|
||||
json.recipes @recipes do |r|
|
||||
json.extract! r, :id, :name, :rating, :yields, :total_time, :active_time, :created_at, :updated_at
|
||||
json.extract! @recipes, :total_count, :total_pages, :current_page
|
||||
json.page_size @recipes.limit_value
|
||||
|
||||
json.tags r.tag_names
|
||||
end
|
||||
json.recipes @recipes do |r|
|
||||
json.extract! r, :id, :name, :rating, :yields, :total_time, :active_time, :created_at, :updated_at
|
||||
|
||||
json.tags r.tag_names
|
||||
end
|
||||
|
||||
end
|
@ -1,31 +1,34 @@
|
||||
json.cache_root! [@recipe] do
|
||||
|
||||
json.extract! @recipe, :id, :name, :rating, :yields, :total_time, :active_time, :created_at, :updated_at, :step_text
|
||||
json.extract! @recipe, :id, :name, :rating, :yields, :total_time, :active_time, :created_at, :updated_at, :step_text
|
||||
|
||||
json.rendered_steps MarkdownProcessor.render(@recipe.step_text)
|
||||
json.rendered_steps MarkdownProcessor.render(@recipe.step_text)
|
||||
|
||||
json.tags @recipe.tag_names
|
||||
json.tags @recipe.tag_names
|
||||
|
||||
json.ingredients @recipe.recipe_ingredients do |ri|
|
||||
json.extract! ri, :id, :ingredient_id, :display_name, :name, :quantity, :units, :preparation, :sort_order
|
||||
json.ingredients @recipe.recipe_ingredients do |ri|
|
||||
json.extract! ri, :id, :ingredient_id, :display_name, :name, :quantity, :units, :preparation, :sort_order
|
||||
|
||||
json.ingredient do
|
||||
if ri.ingredient.nil?
|
||||
json.null!
|
||||
else
|
||||
json.extract! ri.ingredient, :id, :name, :density, :notes
|
||||
json.ingredient do
|
||||
if ri.ingredient.nil?
|
||||
json.null!
|
||||
else
|
||||
json.extract! ri.ingredient, :id, :name, :density, :notes
|
||||
end
|
||||
end
|
||||
|
||||
json._destroy false
|
||||
end
|
||||
|
||||
json.nutrition_data do
|
||||
json.errors @recipe.nutrition_data.errors
|
||||
|
||||
json.nutrients NutritionData::NUTRIENTS.select { |_, v| v.present? } do |name, label|
|
||||
json.name name
|
||||
json.label label
|
||||
json.value @recipe.nutrition_data.send(name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
json._destroy false
|
||||
end
|
||||
|
||||
json.nutrition_data do
|
||||
json.errors @recipe.nutrition_data.errors
|
||||
|
||||
json.nutrients NutritionData::NUTRIENTS.select { |_, v| v.present? } do |name, label|
|
||||
json.name name
|
||||
json.label label
|
||||
json.value @recipe.nutrition_data.send(name)
|
||||
end
|
||||
|
||||
end
|
@ -24,6 +24,10 @@ module Parsley
|
||||
# -- all .rb files in that directory are automatically loaded.
|
||||
config.load_defaults 5.2
|
||||
|
||||
if ENV['RAILS_USE_MEMCACHE'] == 'true'
|
||||
config.cache_store = :mem_cache_store, ENV['RAILS_MEMCACHE_HOST'] || 'memcache'
|
||||
end
|
||||
|
||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
||||
config.time_zone = 'Central Time (US & Canada)'
|
||||
|
@ -14,11 +14,16 @@ Rails.application.configure do
|
||||
# Show full error reports.
|
||||
config.consider_all_requests_local = true
|
||||
|
||||
memcache_enabled = ENV['RAILS_USE_MEMCACHE'] == 'true'
|
||||
|
||||
# Enable/disable caching. By default caching is disabled.
|
||||
if Rails.root.join('tmp/caching-dev.txt').exist?
|
||||
if Rails.root.join('tmp/caching-dev.txt').exist? || memcache_enabled
|
||||
config.action_controller.perform_caching = true
|
||||
|
||||
config.cache_store = :memory_store
|
||||
unless memcache_enabled
|
||||
config.cache_store = :memory_store
|
||||
end
|
||||
|
||||
config.public_file_server.headers = {
|
||||
'Cache-Control' => 'public, max-age=172800'
|
||||
}
|
||||
|
@ -8,12 +8,21 @@ services:
|
||||
- POSTGRES_USER=parsley
|
||||
volumes:
|
||||
- sql-data:/var/lib/postgresql/data
|
||||
|
||||
memcache:
|
||||
image: memcached:1.5.4-alpine
|
||||
command: memcached -m 512
|
||||
|
||||
web:
|
||||
build: .
|
||||
environment:
|
||||
- RAILS_USE_MEMCACHE=true
|
||||
- RAILS_LOG_TO_STDOUT=true
|
||||
ports:
|
||||
- "3000:80"
|
||||
links:
|
||||
- postgres
|
||||
|
||||
volumes:
|
||||
sql-data:
|
||||
driver: local
|
@ -1,3 +1,6 @@
|
||||
env RAILS_LOG_TO_STDOUT;
|
||||
env RAILS_USE_MEMCACHE;
|
||||
env RAILS_MEMCACHE_HOST;
|
||||
env PARSLEY_DB_HOST;
|
||||
env PARSLEY_DB_USER;
|
||||
env PARSLEY_DB_PASSWORD;
|
||||
|
Loading…
Reference in New Issue
Block a user