Using the latest 7.x-2.x code

When looking at the http requests on a page, I'm seeing emit.php called twice when viewing one node. The second call has an array of 2 incidents, including the one that was sent before.

Comments

pwolanin’s picture

Analyzing the JS code - it should NOT be using Drupal behaviors for this - jsut invoke the callback when the DOM is ready.

loze’s picture

Issue summary: View changes

I know this issue is old, but I am seeing something related to this. any javascript that loads ajax data, such as flagging, is calling emit.php.

loze’s picture

Title: emit.php called twice on one page. » emit.php is being called for every ajax call
tripper54’s picture

Status: Active » Needs review
StatusFileSize
new1.73 KB

Patch attached - checks context, only attaches behaviour in the case of a 'document' context. I'm not sure if this is the _correct_ approach, but it works for me.

tripper54’s picture

Maybe interestingly for some, I came across this error because my production servers were reporting php 'Input variables exceeded xxx' warnings.

My page has a few blocks that refresh periodically via ajax callbacks. These were also triggering a call to emit.php , each time appending a new event to the POST data.

So if people leave a page open and walk away from their computer for a few hours, the POST data with each emit.php grows and grows until it exceeds php's max_input_vars value.

Considering I was getting 10 - 20 warnings per minute, I'm looking forward to taking a large load off my servers now that I've found this bug!

loze’s picture

It looks like it working for me too. Thanks tripper54!

paulihuhtiniemi’s picture

StatusFileSize
new3.45 KB

Maybe we could use jQuery .once() method, I think that's the usual way to prevent javascript being executed multiple times?

Here's a patch adds the following wrapper:

$('body').once('radioactivity-emit', function () {
	...
});
corbacho’s picture

I prefer also the use of $('body').once, as it's used for example in Drupal core's JS files for one-time- execution functions.

Getting rid of Drupal.behaviors, it's normally good idea for these type of one-time-executions, as @pwolanin suggested, but in this case it *could* be problematic because the code reads from Drupal.settings and those variables probably are still not initialized. (Although I haven't tested myself)

paulihuhtiniemi’s picture

StatusFileSize
new3.73 KB

Updated the patch, this.config is not available in emitDefault()

  • Commit 879b742 on 7.x-2.x by tcmug:
    Issue #1871656: emit.php is being called for every ajax call. Make...
tcmug’s picture

This needed to be fixed in a different way. The patch would have caused content loaded with ajax not to emit at all. I have fixed this in the latest dev version by using hook_ajax_render_alter() function to add the settings generated by Radioactivity to the ajax call. This will cause the settings.radioactivity.emitters to contain the proper emitters for each ajax call :)

At least ajaxed views pager works well, views infinite pager not so well - that one is a bit bitchy.

Ravenight’s picture

I am seeing the same thing but I am using Authcache. I just upgraded to 7.x-2.x and every time authcache makes a AJAX call emit is still being called. I am also using Memcache storage but when I run the CRON I am getting +70 added to a node vs. the +10 that it should be and I found 6 Ajax calls on the page + the initial emit.

loze’s picture

The latest dev version does not seem to fix this for me as claimed in #11.
i.e. Flagging a node from the node view page does 2 additional emit.php calls (I expected it not to do any)

The patch in #10 does work for the time being.

Ravenight’s picture

Update:
I am running 7.x-2.x-dev and the update mentioned in #11 did not work for me. I reverted the updates done in #11 to radioactivity.js by downloading the the 7.x-2.9 radioactivity.js file and then patched that radioactivity.js with the file from #9 here.

Everything seems to be working in regards to the AJAX calls not running emit.php on every AJAX request.

This works for me as I only want it to be called when the page loads the first time. As I said before, I am caching the page with authcache and putting the emitter into memcache and updating the field on a cron run. All of these things are working well together on my end now.

There may be use-cases that #9 messes with but in my case it works.

loze’s picture

Status: Needs review » Needs work

any update on this?

tcmug’s picture

There is some work done for this in the latest commits to the 2.x branch. At least flags on my local tests no longer cause any extra calls. Can any of you folks verify? :)

Ravenight’s picture

I just downloaded the latest -DEV and it seems to have corrected this issue on my site.

tripper54’s picture

I can also confirm the latest dev seems to fix this on my site.