Comments (11)
Hi @oyeanuj ,
The motivation behind Panko is to achieve better performance at serializing ActiveRecord objects than ActiveModelSerializers (If you want to read how this done - feel free to read: https://github.com/yosiat/panko_serializer/wiki/Design-Choices)
Currently, Panko is 20% compatible with AMS 0.9.7 - you can create serializer, specify relationships - the simple things. the complicated things like embed :ids
, root elements, etc aren't supported.
Today, I am working on making Panko more stable and doing some real load tests, once it's all finished Panko will be released officially and it will have documentation.
If you have more questions/suggestions, feel free.
from panko_serializer.
@yosiat This sounds exciting, thank you for pointing me to the writeup! I am looking forward to be able to try this, especially since I am on the abandoned AMS 0.9x train.
Maybe I'll mention the things that I liked and feel like are missing from AMS experience so that you can consider incorporating some version of them in panko
:
-
In terms of usability, how AMS infers the serializer based on the model type of the entity. So
render json: @posts
in the controller would automatically use thePostSerializer
. -
Again in terms of usability and mental models, I like how associations automatically work within serializers, like how they work in models. Even the polymorphic ones.
Being able to say something like this below would be super cool in panko
.
class UserSerializer < Panko::Serializer
attributes :name, :age, :email
has_many :posts,
only: [:title, :postable]
def name
"#{object.first_name} #{object.last_name}"
end
end
class PostSerializer < Panko::Serializer
attributes :post_id, :title
has_one :postable,
polymorphic: true,
only: [:images, :audio, text: [:body]]
end
# This example would also have ImageSerializer, AudioSerialize, TextSerializer..
#...called in MembersController
paginate json: @members
-
You've already mentioned
embeds
in the comment above, but again I imagine, critical for most people? -
Finally, caching. AMS hasn't had a clear caching solution which really hurts performance when dealing with complex objects.
Thoughts?
from panko_serializer.
Hi!
Panko was build to be minimal so I can get it running at my workplace and get performance improvements. therefore the features you will see in panko are minimal (and there is a new feature for some specific case).
- Inference (first and second feature) - I want to add those before the first stable release.
embeds
aren't supported - embedding simple ids should be fairly simple to implement today.- Caching - as far I see it, it's performance feature - I don't see any reason to implement this because Panko deals greatly with complex objects.
I added the inference feature requests as issues and tagged them for "Stable Release" milestone - https://github.com/yosiat/panko_serializer/milestone/1
If you want, we can discuss some missing features and I'll help you implement them via PR.
from panko_serializer.
@yosiat Thank you for the reply, all of this sounds good.
On caching: I think especially since Panko
already greatly improves performance, addressing caching would be super on point (whether through a PR/Readme notes/strategy/recipe). Just my $0.02.
One more thing that came to my mind that I see used: camelCasing of keys which is super useful in integrating with JS code.
Looking forward to the stable release!
from panko_serializer.
@yosiat Just wanted to get a sense of when do you see the inference features becoming a part of the library? It would help me decide if I can start migrating now or need to wait.
Excited to be able to move to Panko!
from panko_serializer.
@oyeanuj it was crucial for me before working on the inference to make sure panko is working correctly, safely and fast on production.
Now that I finish with the above, I plan this week to work on the inference.
Just to make sure we are talking about the same thing, instead of writing:
render json: Panko::ArraySerializer.new(posts, each_serializer: PostSerializer).to_json
you will write:
render json: posts
The only issue I see is if Panko & AMS are installed on the same project (which make sense, during a migration process, half deployment, etc) who will take precedence?
from panko_serializer.
@yosiat Yes, talking about the same thing. Additionally, if in another serializer, I write:
has_many :posts,
except: [:body]
It should ideally be able to infer that the association has PostSerializer
associated and be able to include/exclude attributes?
As for precedence, do you think a configuration setting in controller or initializer would be enough? Maybe something along the lines of?
use_panko_as_serializer_for [Post, Comment]
from panko_serializer.
@yosiat It seems like the example I was talking about above might be achieved with Nested Filters but I have a couple of questions on it -
- Can we use
except
,include
instead ofonly
in nested filters? - Is there a way to specify that nesting with a serializer as well? Or does the performance constraint dictate it to be outside?
Here is an example of what inside the serializer would look like -
class PostSerializer < Panko::Serializer
attributes :post_id, :title
has_one :postable,
polymorphic: true,
only: [:images, :audio, text: [:body]]
end
from panko_serializer.
- Passing inline filters to relationships is supported as of today.
- Nested Filters support only (same as to include) and except.
from panko_serializer.
@yosiat Got it, that means the a snippet like this is supported?
has_many :comments,
only: [:id, :author_name]
Maybe this can be added to the docs as well, in the Associations page?
from panko_serializer.
@oyeanuj the issue is getting longer :)
let's try to close it.. the has_many
example with filters should work all we need is:
- simple unit test to make sure we won't have regressions here
- docs in Associations page.
LMK if you want to make PR if not, I'll make one over the weekend.
from panko_serializer.
Related Issues (20)
- Delegate + aliases not working as expected HOT 1
- Adding a custom root name for array serializer HOT 1
- Relax `oj` dependency HOT 3
- Is anyone actively maintaining this project? HOT 2
- Using ActiveRecord's pluck when possible
- Serialize attributes which is used `serialize` in active model definition
- Benchmarks task not working HOT 1
- How do I selectively display a key/value pair? HOT 2
- Alias declaration is ignored when method is added HOT 2
- Migration from AMS HOT 3
- Filter on array serializer? HOT 4
- Conditionally include associations in JSON response HOT 3
- Rendering recursive relations HOT 2
- Add context to relations has_one/has_many
- Ability to skip nil values HOT 2
- Attrribute methods not running HOT 4
- how to customize association sorting? HOT 2
- Can't compile on windows. Fix seems easy. HOT 5
- Serialization of single object with context / options HOT 2
- How to use a raw JSON string inside a serializer? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from panko_serializer.