Skip to content

Commit

Permalink
[Bench] Remove jsonapi-serializer from benchmark
Browse files Browse the repository at this point in the history
The author of it requested to remove it from benchmark.
#104 (comment)
  • Loading branch information
okuramasafumi committed Jul 16, 2022
1 parent a01cc99 commit 72e42e0
Showing 1 changed file with 0 additions and 70 deletions.
70 changes: 0 additions & 70 deletions benchmark/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
gem "jbuilder"
gem 'turbostreamer'
gem "jserializer"
gem "jsonapi-serializer" # successor of fast_jsonapi
gem "multi_json"
gem "panko_serializer"
gem "pg"
Expand Down Expand Up @@ -201,67 +200,6 @@ def commenter_names
end
end

# --- JSONAPI:Serializer serializers / (successor of fast_jsonapi) ---

class JsonApiStandardCommentSerializer
include JSONAPI::Serializer

attribute :id
attribute :body
end

class JsonApiStandardPostSerializer
include JSONAPI::Serializer

# set_type :post # optional
attribute :id
attribute :body
attribute :commenter_names

attribute :comments do |post|
post.comments.map { |comment| JsonApiSameFormatCommentSerializer.new(comment) }
end
end

# --- JSONAPI:Serializer serializers that format the code the same flat way as the other gems here ---

# code to convert from JSON:API output to "flat" JSON, like the other serializers build
class JsonApiSameFormatSerializer
include JSONAPI::Serializer

def as_json(*_options)
hash = serializable_hash

if hash[:data].is_a? Hash
hash[:data][:attributes]

elsif hash[:data].is_a? Array
hash[:data].pluck(:attributes)

elsif hash[:data].nil?
{ }

else
raise "unexpected data type #{hash[:data].class}"
end
end
end

class JsonApiSameFormatCommentSerializer < JsonApiSameFormatSerializer
attribute :id
attribute :body
end

class JsonApiSameFormatPostSerializer < JsonApiSameFormatSerializer
attribute :id
attribute :body
attribute :commenter_names

attribute :comments do |post|
post.comments.map { |comment| JsonApiSameFormatCommentSerializer.new(comment) }
end
end

# --- Panko serializers ---
#

Expand Down Expand Up @@ -419,8 +357,6 @@ def to_json
end.target!
end
jserializer = Proc.new { JserializerPostSerializer.new(posts, is_collection: true).to_json }
jsonapi = proc { JsonApiStandardPostSerializer.new(posts).to_json }
jsonapi_same_format = proc { JsonApiSameFormatPostSerializer.new(posts).to_json }
panko = proc { Panko::ArraySerializer.new(posts, each_serializer: PankoPostSerializer).to_json }
primalize = proc { PrimalizePostsResource.new(posts: posts).to_json }
rails = Proc.new do
Expand All @@ -441,8 +377,6 @@ def to_json
fast_serializer: fast_serializer,
jbuilder: jbuilder, # different order
jserializer: jserializer,
jsonapi: jsonapi, # nested JSON:API format
jsonapi_same_format: jsonapi_same_format,
panko: panko,
primalize: primalize,
rails: rails,
Expand All @@ -462,8 +396,6 @@ def to_json
x.report(:fast_serializer, &fast_serializer)
x.report(:jbuilder, &jbuilder)
x.report(:jserializer, &jserializer)
x.report(:jsonapi, &jsonapi)
x.report(:jsonapi_same_format, &jsonapi_same_format)
x.report(:panko, &panko)
x.report(:primalize, &primalize)
x.report(:rails, &rails)
Expand All @@ -484,8 +416,6 @@ def to_json
x.report(:fast_serializer, &fast_serializer)
x.report(:jbuilder, &jbuilder)
x.report(:jserializer, &jserializer)
x.report(:jsonapi, &jsonapi)
x.report(:jsonapi_same_format, &jsonapi_same_format)
x.report(:panko, &panko)
x.report(:primalize, &primalize)
x.report(:rails, &rails)
Expand Down

0 comments on commit 72e42e0

Please sign in to comment.