Multiple calls to /lib/ajax/service.php problem

Re: Multiple calls to /lib/ajax/service.php problem

by Juan Salazar -
Number of replies: 0
Figured out the error. In my/lib.php there is a function called my_copy_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') that is called every time a user is logged in and moodle needs to instantiate a new dashboard. The key is in these lines here:

$blockinstances = $DB->get_records('block_instances', array('parentcontextid' => $systemcontext->id,
'pagetypepattern' => $pagetype,
'subpagepattern' => $systempage->id));
$newblockinstanceids = [];
foreach ($blockinstances as $instance) {
$originalid = $instance->id;
unset($instance->id);
$instance->parentcontextid = $usercontext->id;
$instance->subpagepattern = $page->id;
$instance->timecreated = time();
$instance->timemodified = $instance->timecreated;
$instance->id = $DB->insert_record('block_instances', $instance);
$newblockinstanceids[$originalid] = $instance->id;
$blockcontext = context_block::instance($instance->id); // Just creates the context record
$block = block_instance($instance->blockname, $instance);
if (!$block->instance_copy($originalid)) {
debugging("Unable to copy block-specific data for original block instance: $originalid
to new block instance: $instance->id", DEBUG_DEVELOPER);
}
}

which pretty much says that block instances are copied from a parent context, which are then appended to the new user's dashboard. My parent context just happened to be littered with extraneous amounts of blocks. I've deleted them and the problem went away.