test/benchmark/controllers.rb in active_model_serializers-0.10.0 vs test/benchmark/controllers.rb in active_model_serializers-0.10.1

- old
+ new

@@ -1,41 +1,40 @@ -class PostController < ActionController::Base - POST = +class PrimaryResourceController < ActionController::Base + PRIMARY_RESOURCE = begin - updated_at = Time.current if ENV['BENCH_STRESS'] - comments = (0..50).map do |i| - Comment.new(id: i, body: 'ZOMG A COMMENT', updated_at: updated_at + i) + has_many_relationships = (0..50).map do |i| + HasManyRelationship.new(id: i, body: 'ZOMG A HAS MANY RELATIONSHIP') end else - comments = [Comment.new(id: 1, body: 'ZOMG A COMMENT', updated_at: updated_at)] + has_many_relationships = [HasManyRelationship.new(id: 1, body: 'ZOMG A HAS MANY RELATIONSHIP')] end - author = Author.new(id: 42, first_name: 'Joao', last_name: 'Moura') - Post.new(id: 1337, title: 'New Post', blog: nil, body: 'Body', comments: comments, author: author) + has_one_relationship = HasOneRelationship.new(id: 42, first_name: 'Joao', last_name: 'Moura') + PrimaryResource.new(id: 1337, title: 'New PrimaryResource', virtual_attribute: nil, body: 'Body', has_many_relationships: has_many_relationships, has_one_relationship: has_one_relationship) end def render_with_caching_serializer toggle_cache_status - render json: POST, serializer: CachingPostSerializer, adapter: :json, meta: { caching: perform_caching } + render json: PRIMARY_RESOURCE, serializer: CachingPrimaryResourceSerializer, adapter: :json, meta: { caching: perform_caching } end def render_with_fragment_caching_serializer toggle_cache_status - render json: POST, serializer: FragmentCachingPostSerializer, adapter: :json, meta: { caching: perform_caching } + render json: PRIMARY_RESOURCE, serializer: FragmentCachingPrimaryResourceSerializer, adapter: :json, meta: { caching: perform_caching } end def render_with_non_caching_serializer toggle_cache_status - render json: POST, adapter: :json, meta: { caching: perform_caching } + render json: PRIMARY_RESOURCE, adapter: :json, meta: { caching: perform_caching } end def render_cache_status toggle_cache_status # Uncomment to debug # STDERR.puts cache_store.class # STDERR.puts cache_dependencies - # ActiveSupport::Cache::Store.logger.debug [ActiveModelSerializers.config.cache_store, ActiveModelSerializers.config.perform_caching, CachingPostSerializer._cache, perform_caching, params].inspect + # ActiveSupport::Cache::Store.logger.debug [ActiveModelSerializers.config.cache_store, ActiveModelSerializers.config.perform_caching, CachingPrimaryResourceSerializer._cache, perform_caching, params].inspect render json: { caching: perform_caching, meta: { cache_log: cache_messages, cache_status: cache_status } }.to_json end def clear ActionController::Base.cache_store.clear @@ -74,11 +73,11 @@ end end end Rails.application.routes.draw do - get '/status(/:on)' => 'post#render_cache_status' - get '/clear' => 'post#clear' - get '/caching(/:on)' => 'post#render_with_caching_serializer' - get '/fragment_caching(/:on)' => 'post#render_with_fragment_caching_serializer' - get '/non_caching(/:on)' => 'post#render_with_non_caching_serializer' + get '/status(/:on)' => 'primary_resource#render_cache_status' + get '/clear' => 'primary_resource#clear' + get '/caching(/:on)' => 'primary_resource#render_with_caching_serializer' + get '/fragment_caching(/:on)' => 'primary_resource#render_with_fragment_caching_serializer' + get '/non_caching(/:on)' => 'primary_resource#render_with_non_caching_serializer' end