MDL-75667 admin: Avoid DB calls within loops on admin/blocks.php
This commit is contained in:
+11
-6
@@ -74,9 +74,15 @@
|
||||
|
||||
/// Get and sort the existing blocks
|
||||
|
||||
if (!$blocks = $DB->get_records('block', array(), 'name ASC')) {
|
||||
throw new \moodle_exception('noblocks', 'error'); // Should never happen.
|
||||
}
|
||||
$sql = "SELECT b.* , COUNT(DISTINCT binst.id) as totalcount, COUNT(DISTINCT bcinst.id) as courseviewcount
|
||||
FROM {block} b
|
||||
LEFT JOIN {block_instances} binst ON binst.blockname = b.name
|
||||
LEFT JOIN {block_instances} bcinst ON bcinst.blockname = b.name AND bcinst.pagetypepattern = 'course-view-*'
|
||||
GROUP BY b.id, binst.blockname, bcinst.blockname
|
||||
ORDER BY b.name ASC";
|
||||
if (!$blocks = $DB->get_records_sql($sql)) {
|
||||
throw new \moodle_exception('noblocks', 'error'); // Should never happen.
|
||||
}
|
||||
|
||||
$incompatible = array();
|
||||
|
||||
@@ -154,9 +160,8 @@
|
||||
// MDL-11167, blocks can be placed on mymoodle, or the blogs page
|
||||
// and it should not show up on course search page
|
||||
|
||||
$totalcount = $DB->count_records('block_instances', array('blockname'=>$blockname));
|
||||
$count = $DB->count_records('block_instances', array('blockname'=>$blockname, 'pagetypepattern'=>'course-view-*'));
|
||||
|
||||
$totalcount = $blocks[$blockid]->totalcount;
|
||||
$count = $blocks[$blockid]->courseviewcount;
|
||||
if ($count>0) {
|
||||
$blocklist = "<a href=\"{$CFG->wwwroot}/course/search.php?blocklist=$blockid&sesskey=".sesskey()."\" ";
|
||||
$blocklist .= "title=\"$strshowblockcourse\" >$totalcount</a>";
|
||||
|
||||
Reference in New Issue
Block a user