Hi,

We're experiencing a big performance issue on Node edit pages with lots of Atoms attached, via the Atom Reference field. In our case scenario, there can be nodes with dozens and even hundreds of atoms attached to a single node. The issue shows up when you try to edit the node. i.e.: a node with about 100 atoms attached, takes up to 3 minutes to load.

We tracked down the issue to be in atom_reference.js file, where it is trying to do an AJAX call for every embedded Atom to load it, check for permissions, and then alter the DOM to add buttons to view/edit/remove the Atom.

We are working on a patch to move some of this resource expensive logic to be server side, during the generation of the form; rather than on the client's browser.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

esolano created an issue. See original summary.

jcisio’s picture

Version: 7.x-1.6 » 7.x-1.x-dev

While we can move the logic into server side, we can still do it client side by using a single AJAX call to fetch all atoms. I think it will have less code rewrite.

gifad’s picture

I had this issue on a site with huge (100+) atom references;
I found the cause not being fetch atoms (which is fast), but the "installation" of CTools buttons, behaviors, etc...
Removing all CTools stuff (including CTools modal frames), I have now a load time < 10 seconds (2" server build time, 4" to 8" client build time, depending on thumbnails being cached or not).

I have no time to build a patch now (and it would probably not be committed...), so I just attached the full module I use.
(I removed the "Edit" button, since the "View" button opens the atom/{sid} page in a new tab)

[Edit : my use case is atom_reference fields as items of scald_gallery atoms : Not sure if nodes are significantly slower than atoms ? ]

esolano’s picture

Hi there,

Here's our take on this issue. The patch transfers some of the Atom loading logic to the server side; while it keeps all the other CTools goodies. This way, we managed to bring the wait time down to about 8 secs.

We hope this helps.

ed.hollinghurst’s picture

I found the patch in #4 worked great but didn't work if I had multiple atom references on one page.

The patch below should fix this.

gifad’s picture

Status: Active » Needs review
FileSize
6.96 KB

Patch at #6 works great, but does not apply to current dev — re-rolled

ed.hollinghurst’s picture

I've made some more updates to the patch today as I also wanted to add support for multi-value fields. Previously there was an issue when the 'add another item' button was clicked.

nagy.balint’s picture

Hmm, Am i missing something? Or there was never a need for a fetchAtom in there as the image was always added on the server?

nagy.balint’s picture

Can anyone help reviewing this patch?

nagy.balint’s picture

Status: Needs review » Needs work

Okay, after further tests, it seems that the patch will need some further work.

The atom reference js needs the atoms in the field to be in the Drupal.dnd.Atoms array. (At the moment this is cause of the context override).

However since the fetchAtom is now removed in this patch, that wont happen. Of course if the inserted atom is on the first page of the dnd library then its fine, but otherwise its not.

So the solution could be to create a new function in dnd module that creates data for a specific atom, and then that can be called in scald_dnd_library module and also in the atom reference module, as both depends on the dnd module.
Then we can probably use drupal_add_js to add the items in the atom reference as js settings, and hopefully it will be merged together with the items coming from the library.

gifad’s picture

The atom reference js needs the atoms in the field to be in the Drupal.dnd.Atoms array.

Can you elaborate on this ?
I can't figure a sequence where atom_reference.js would reference an atom not present in Drupal.dnd.Atoms.

Do you get a js error ? something that just doesn't work ?

nagy.balint’s picture

Drupal.dnd.Atoms only contains the atoms that are on the first page of the dnd library.

So if you have atoms in the atom reference that is not on the first page of the library, then it wont exist.

nagy.balint’s picture

I tried to find if those atoms in the atom reference are added in the Drupal.dnd.Atoms somewhere on the server, but could not find it. As the fetchAtom call in JS is removed in this patch, and that causes most of the performance improvement, it wont really be done from js.

nagy.balint’s picture

If anyone can work on this to finish it, then I could make a new release.

gifad’s picture

@nagy.balint : Drupal.dnd.Atoms is used only as a temporary (cache) storage for the drag and drop process.

I'm using #8 for 6 months without any flaw.

If you get any error or unexpected behavior, please provide steps to reproduce, etc...

gifad’s picture

Status: Needs work » Needs review

nagy.balint’s picture

I think i described it well enough in #11 and #13.

If the atom that is referenced in the atom reference is not on the first page of the dnd, then it does not work properly, for example when we enable the context override.