Hi,
I’m running into a memory performance issue with Active Record
associations.
I’m tinkering with Redmine, a rails-based project management
application. The central model in the application is ‘Project’ which
associates via has_many to model Issue. One of the things you can do
with Projects is copy them. In a nutshell, copy is implemented like
this (in class Project):
def copy(other_project)
other_project.issues.each do |other_issue|
self.issues << other_issue.copy
end
self.save
end
The problem is that issues are themselves complex objects, and for a
project with many issues (several thousand), self.issues grows to the
point of exhausting memory and swap on the box, effectively making a DOS
attack out of this function. So the question is, is there an idiomatic
Active Record solution to this problem? Perhaps committing and flushing
the association list every N adds?
Thanks in advance for any advice.