From b818722102950eb3d041f562c5a1db508e2ea1ca Mon Sep 17 00:00:00 2001 From: Chase Date: Tue, 24 Oct 2017 14:36:04 -0400 Subject: [PATCH] minor perf tweaks --- Gemfile | 2 ++ Gemfile.lock | 4 ++++ app/controllers/annotations_controller.rb | 2 +- app/controllers/articles_controller.rb | 2 +- config/initializers/escapes.rb | 7 +++++++ config/initializers/oj.rb | 1 + 6 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 config/initializers/escapes.rb create mode 100644 config/initializers/oj.rb diff --git a/Gemfile b/Gemfile index f7389ce..7fb0580 100644 --- a/Gemfile +++ b/Gemfile @@ -11,9 +11,11 @@ gem 'rails', '~> 5.1.4' gem 'browser' gem 'devise' +gem 'escape_utils' gem 'fast_blank' gem 'httparty' gem 'nokogiri' +gem 'oj' gem 'pg', '~> 0.18' gem 'pg_query', '>= 0.9.0' gem 'pghero' diff --git a/Gemfile.lock b/Gemfile.lock index 76e12dd..6c21f3b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,7 @@ GEM equalizer (0.0.11) erubi (1.7.0) erubis (2.7.0) + escape_utils (1.2.1) faker (1.8.4) i18n (~> 0.5) fakeredis (0.6.0) @@ -219,6 +220,7 @@ GEM shellany (~> 0.0) octokit (4.7.0) sawyer (~> 0.8.0, >= 0.5.3) + oj (3.3.8) orm_adapter (0.5.0) parallel (1.12.0) parser (2.4.0.0) @@ -464,6 +466,7 @@ DEPENDENCIES byebug coveralls devise + escape_utils faker fakeredis fast_blank @@ -478,6 +481,7 @@ DEPENDENCIES memory_profiler mutant-rspec nokogiri + oj pg (~> 0.18) pg_query (>= 0.9.0) pghero diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index dcacc66..e5ec555 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -8,7 +8,7 @@ def create user = User.find(article_and_user[:user_id].to_i) annotation = Annotation.new(annotation_params.merge(user: user, article: article)) if annotation.save - render json: { success: 'annotation saved' }, status: 200 + render json: { success: 'annotation saved' }, status: 201 else render json: { failure: annotation.errors }, status: 400 end diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 194e0a5..afc5b3d 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -49,7 +49,7 @@ def validate_search def find_article_and_annotations @article ||= Article.find_by(uuid: show_params['id']) - @annotations ||= Annotation.where(article: @article) + @annotations = Annotation.where(article: @article) end def article_params diff --git a/config/initializers/escapes.rb b/config/initializers/escapes.rb new file mode 100644 index 0000000..80f2ab8 --- /dev/null +++ b/config/initializers/escapes.rb @@ -0,0 +1,7 @@ +begin + require 'escape_utils/html/rack' # to patch Rack::Utils + require 'escape_utils/html/erb' # to patch ERB::Util + require 'escape_utils/html/cgi' # to patch CGI +rescue LoadError + Rails.logger.info 'Escape_utils is not in the gemfile' +end \ No newline at end of file diff --git a/config/initializers/oj.rb b/config/initializers/oj.rb new file mode 100644 index 0000000..a58f11f --- /dev/null +++ b/config/initializers/oj.rb @@ -0,0 +1 @@ +Oj.optimize_rails() \ No newline at end of file