You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue maybe have some overlaps with this and this
I was working on a project that uses administrate and noticed a performance issue with the Field::BelongsTo, where the associated record took too long to load up in the edit form. For more context the association in question is as follows:
class Employee
belongs_to :company
end
class Company
has_many :employees
end
So in the Employee edit form, I need to select a company that a particular employee belongs to. As the number of companies created increased I noticed a considerable delay in the edit form to the point where the page was unusable for a minute or so. Tracking down the issue led me to this line of code here
In a situation where thousands of associated objects need to be iterated upon one could imagine how this will overtime cause a significant lag in performance.
My current resolution was to create a custom field as explained in your documentation, implementing the .find_each query method and immediately noticed a significant improvement.
What I propose is the use of the active record method.find_each as defined here. This is a memory-friendly approach to iterating over large number of records.
Hopefully during the weekend I'll have the time to submit my suggestion upstream as PR with screenshots of benchmarked improvements but given that my solution is pretty simple I believe anyone with the time on their hands can easily implement this upstream.
The text was updated successfully, but these errors were encountered:
paayaw0
changed the title
Potential peformance improvements with Field::
Potential peformance improvements with Field::BelongsTo
May 31, 2024
This issue maybe have some overlaps with this and this
I was working on a project that uses administrate and noticed a performance issue with the Field::BelongsTo, where the associated record took too long to load up in the edit form. For more context the association in question is as follows:
So in the Employee edit form, I need to select a company that a particular employee belongs to. As the number of companies created increased I noticed a considerable delay in the edit form to the point where the page was unusable for a minute or so. Tracking down the issue led me to this line of code here
In a situation where thousands of associated objects need to be iterated upon one could imagine how this will overtime cause a significant lag in performance.
My current resolution was to create a custom field as explained in your documentation, implementing the
.find_each
query method and immediately noticed a significant improvement.What I propose is the use of the active record method
.find_each
as defined here. This is a memory-friendly approach to iterating over large number of records.Hopefully during the weekend I'll have the time to submit my suggestion upstream as PR with screenshots of benchmarked improvements but given that my solution is pretty simple I believe anyone with the time on their hands can easily implement this upstream.
The text was updated successfully, but these errors were encountered: