2

I'm using using entity reference, field collection , and field collection table modules on a site that features "courses" and "lessons" as content types. A field collection with unlimited values is embedded in the course content type, and it contains two fields: a text field for "section" and an entity reference field for "lesson". This allows the same lessons to be reused in different courses, while appearing under a different section. (see screen for reference).

This works pretty well, but performance when editing course nodes starts to degrade significantly after about 30 lessons are added to a course. At 100 lessons, it takes about 15 seconds to load a course for editing. With 140 lessons in a course, it takes about 22 seconds to edit a course node. I'm testing locally on a new D7 test site with devel-generated content.

Questions:

(1) Are there any obvious steps I should take to improve performance with field collections?

(2) As an alternative to field collections, would creating a compound field in code likely improve performance significantly?

(3) For testing performance generally, is there a simple profiling tool I can use with Drupal?

Example of a small course with 10 lessons added as field collections:

example of a small course with 10 lessons added as field collections

7
  • As an alternative to field collections, would creating a compound field in code likely improve performance significantly? Always depends on how much data you have, but yes, almost certainly. If you have a field collection with 5 fields, that's at least 5 db queries (or joins, if you're lucky) to get the data. With a compound field that would be reduced to a single query
    – Clive
    Commented Jan 8, 2014 at 16:33
  • Thanks for the input. It's kind of a daunting amount of code at first glance, but I guess it breaks down into smaller pieces that aren't too bad. I'll try to find time to give it a shot.
    – Dave Bruns
    Commented Jan 8, 2014 at 17:37
  • Yeah it can be a bit daunting, the field example module in Examples will be very useful if you decide to go down that route
    – Clive
    Commented Jan 8, 2014 at 17:47
  • You are using the wrong tool for the job. Lessons should have a reference to courses, not the other way around. Use a custom entity type and kill field_collection. Commented Jan 8, 2014 at 20:02
  • That's the way it is configured now on a production site. However, there is a new requirement to allow lessons to be re-used across multiple courses. Therefore, each course needs custom sections and its own sort order for lessons that belong to it. Any suggestions for how to approach?
    – Dave Bruns
    Commented Jan 8, 2014 at 20:06

1 Answer 1

1

Update: In the end, I abandoned field collections and created a custom compound field that is attached to the 'course' content type.

This pretty much eliminated the performance problems. Opening a course node with 130 lessons in the field now takes 3-6 seconds, depending on the server.

And because the field is unlimited multivalue, the delta works a sorting mechanism for the lessons in views, etc.

I also added code to add more than one item at a time as seen here:

Slow "Add another item" with unlimited valued fields

When there are a lot of items in the field, adding a new item ends up taking a lot of time.

Good resources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.