This is not the answer you are looking for. I'm sure this is possible somehow, but you will fight against the grain of how polymorphism was developed in ActiveRecord, and this is likely to cause a load.
The first question that comes to me is why? You are asking for performance optimization. Do you see a performance problem? Have you checked with the toolkit, New Relic, the Ruby profiler, and other tools that this second search is really what kills your performance? If you have not done so, you are probably wasting your time. Predicting performance bottlenecks is an inaccurate science and follows rule 80-20.
If you really have this problem, and you carefully analyzed your logs, your new relic diagrams, you isolated the problem and ran performance tests against it, if you did all this and you "I see a performance problem with this problem, then I would suggested that the denormalization sort solution is likely to give you some improvement.Denormalization is a common tool for optimizing database performance problems.You will store data in more than one place, but your request Wasps will touch fewer tables (faster) with additional overhead while maintaining synchronization of several bits when updating records (more complex application code).
If you could post more details about your example, it would be easier to make some more specific suggestions or provide examples.
Wolfram arnold
source share