Hi, I just noticed that Discourse uses older version of ActiveModelSerializer.
It was released five years ago and I don’t think it’s good.
It seems that it’s planned to fork AMS but there’s a better solution.
My suggestion here to migrate from AMS to Alba, a JSON serializer I created and maintain. Although Alba is not 100% compatible with AMS, the API it offers is similar to AMS and about 10 times faster than latest AMS.
If the maintainers agree on migration, I’ll send a PR.
Could you change 2 or 3 endpoints over to it in PR and run some benchmarks? That may help us to evaluate it
Yes, as Falco mentioned we need to worry about 2 areas here:
Plugin compatibility - many plugins extend serializers, we would like to minimize breaking changes
Performance - changing serializers needs to be backed with hard data.
I recommend looking at some of the serializers involved in topic or topic list pages and using them as testing grounds:
Then use “before” and “after” figures of discoruse bench. It will give you a very accurate feel of the progress made.
The amount of ecosystem disruption we are open to accepting heavily depends on the performance improvement here.
Sorry for the late response.
I believe it makes performance improvements so I’ll run benchmark script.
I didn’t know about serializer plugins. I found one example of plugins that customize serializer.
include_votes? method seems a magic method from AMS since I cannot find where it’s used in the codebase. I think we need some migration in such cases since Alba doesn’t support this behavior.
Keeping compatibility must be important, so if I cannot make Alba compatible with existing plugins, I prefer not moving on.
The magic you’re looking for is
add_to_serializer. You don’t need to make a new serializer.
Maybe this will help: Add to serializer only for staff and current user - #7 by paresy
Ah, thanks, it looks like it just defines some helper methods that returns whether the plugin is enabled or not and the plugin body. I think I can make it compatible with Alba, let me try.
Sorry. I didn’t look closely enough at the original plugin. I think that my hint might not be as helpful as I thought.
If what you’re doing is adding something to existing serializers (like adding a field to the post serializer), then I’ve helped. If you need to add a new route that returns its own information, then you’ll need to do something else.