Home Company Services Portfolio Contact us nav spacer

Simple References

by Roché Compaan posted on Sep 12, 2009 12:20 PM last modified Sep 12, 2009 02:46 PM —

Simple references can speed up your Plone application significantly.

While optimising the import of objects from a CSV file, I re-discovered how slow the Archetypes reference implementation is. In my experience, one rarely queries the reference catalog directly or interrogate the metadata of a relationship. I'm not saying these are not legitimate use cases, only that I rarely need to do this in the applications I write. Most of the time, I simply need to call the accessor of the reference field to get the referenced objects. Even Plone's related content reference field doesn't need to do more than get the referenced content.

Plone's overzealous use of catalogs is often the cause of performance problems, and the reference implementation is no exception. For most use cases, you don't need to do much more than store the UIDs of referenced objects on the source object itself. Years ago I developed SimpleReferenceField to address this problem, and pulled it closer now for this import job. It stores referenced UIDs on the object itself using annotation storage.

Using the original ReferenceField, it took almost 30 minutes to import 4000 instances of a fairly basic Archetype with a single multivalued reference field. It took only 5 minutes to import them using SimpleReferenceField. You can find it here: http://svn.plone.org/svn/collective/SimpleReferenceField/