Moodle

Script running slowly message when a resource is deleted (ajax)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.7, 1.7.1, 1.7.2, 1.8
  • Fix Version/s: 1.7.2, 1.8
  • Component/s: AJAX
  • Labels:
    None
  • Environment:
    IE 6 and 7
    Moodle: 1.7 and more recent
  • Database:
    Any
  • Affected Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE
  • Fixed Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE

Description

IE 6 freezes up attempting to delete activities within a course. When AJAX is disabled, the error resolves.

Activity

Hide
Vy-Shane Sin Fat added a comment -

Confirmed that this happens in both IE 6 and 7. Works fine in Firefox 2.

Show
Vy-Shane Sin Fat added a comment - Confirmed that this happens in both IE 6 and 7. Works fine in Firefox 2.
Hide
Vy-Shane Sin Fat added a comment -

I've looked at the IE process when the error occurs. The memory usage stays fairly constant while the CPU usage goes way up. It doesn't seem like a memory leak caused by our JavaScript code.

I've traced the problem to line 402 in lib/ajax/section_classes.js. The offending line is not being looped. The function is reproduced below:

section_class.prototype.remove_resource = function(el) {

var resourceEl = el.getEl();
var parentEl = resourceEl.parentNode;
if (!parentEl) { return false; }

var resourceCount = this.resources.length;

if (resourceCount == 1) {
if (this.resources[0] == el) { this.resources = new Array(); }
} else {
var found = false;
for (var i=0; i<resourceCount; i++) {
if (found) {
this.resources[i - 1] = this.resources[i];
if (i == resourceCount - 1) { this.resources = this.resources.slice(0, -1); resourceCount--; }
this.resources[i - 1].update_index(i - 1);
} else if (this.resources[i] == el) { found = true; }
}
}
// Remove any extra text nodes to keep DOM clean.
var kids = parentEl.childNodes;

for (var i=0; i<kids.length; i++) {
if (kids[i].nodeType == 3) { YAHOO.log('Removed extra text node.'); parentEl.removeChild(kids[i]); }
}
// Remove the resource.
// FIXME
// Line below is causing IE 6 and 7 to freeze.
parentEl.removeChild(resourceEl);

this.write_sequence_list();
return true;
}

Show
Vy-Shane Sin Fat added a comment - I've looked at the IE process when the error occurs. The memory usage stays fairly constant while the CPU usage goes way up. It doesn't seem like a memory leak caused by our JavaScript code. I've traced the problem to line 402 in lib/ajax/section_classes.js. The offending line is not being looped. The function is reproduced below: section_class.prototype.remove_resource = function(el) { var resourceEl = el.getEl(); var parentEl = resourceEl.parentNode; if (!parentEl) { return false; } var resourceCount = this.resources.length; if (resourceCount == 1) { if (this.resources[0] == el) { this.resources = new Array(); } } else { var found = false; for (var i=0; i<resourceCount; i++) { if (found) { this.resources[i - 1] = this.resources[i]; if (i == resourceCount - 1) { this.resources = this.resources.slice(0, -1); resourceCount--; } this.resources[i - 1].update_index(i - 1); } else if (this.resources[i] == el) { found = true; } } } // Remove any extra text nodes to keep DOM clean. var kids = parentEl.childNodes; for (var i=0; i<kids.length; i++) { if (kids[i].nodeType == 3) { YAHOO.log('Removed extra text node.'); parentEl.removeChild(kids[i]); } } // Remove the resource. // FIXME // Line below is causing IE 6 and 7 to freeze. parentEl.removeChild(resourceEl); this.write_sequence_list(); return true; }
Hide
Vy-Shane Sin Fat added a comment -

I've checked in a temporary change. Deletion of resources will not use ajax anymore until we find a fix for this issue.

Show
Vy-Shane Sin Fat added a comment - I've checked in a temporary change. Deletion of resources will not use ajax anymore until we find a fix for this issue.
Hide
Vy-Shane Sin Fat added a comment -

Adding more watchers in the hope that someone might have an idea for a fix.

Show
Vy-Shane Sin Fat added a comment - Adding more watchers in the hope that someone might have an idea for a fix.
Hide
Andrew Walker added a comment -

Hi,

So far I haven't been able to reproduce this in either IE 6 or 7. Does this require any specific setup of the course? At the moment if I edit resource_class.prototype.delete_button so IE uses the AJAX stuff again deleting resources works as expected for me.

There is one thing I'm unsure about - section_class.prototype.remove_resource is also called when dragging resources around - is this problem only happening for people in the cases where remove_resource is used when the delete button is clicked?

Show
Andrew Walker added a comment - Hi, So far I haven't been able to reproduce this in either IE 6 or 7. Does this require any specific setup of the course? At the moment if I edit resource_class.prototype.delete_button so IE uses the AJAX stuff again deleting resources works as expected for me. There is one thing I'm unsure about - section_class.prototype.remove_resource is also called when dragging resources around - is this problem only happening for people in the cases where remove_resource is used when the delete button is clicked?
Hide
Vy-Shane Sin Fat added a comment -

Hi Andrew,

This is weird. HEAD code is now working for me. 1.7 Stable is still showing the same problem. It's only happening when I delete resources, not when I move them.

Show
Vy-Shane Sin Fat added a comment - Hi Andrew, This is weird. HEAD code is now working for me. 1.7 Stable is still showing the same problem. It's only happening when I delete resources, not when I move them.
Hide
Vy-Shane Sin Fat added a comment -

Seems to have been fixed by a recent update to the YUI libs.

Show
Vy-Shane Sin Fat added a comment - Seems to have been fixed by a recent update to the YUI libs.

People

Vote (0)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: