Improve query speed see BT#4701

skala
Julio Montoya 13 years ago
parent 9ac287cf15
commit d43144389d
  1. 7
      main/newscorm/learnpath.class.php
  2. 26
      main/newscorm/learnpathItem.class.php

@ -260,8 +260,7 @@ class learnpath {
break;
case 1:
default:
require_once 'learnpathItem.class.php';
$oItem = new learnpathItem($row['id'], $user_id, $course_id);
$oItem = new learnpathItem($row['id'], $user_id, $course_id, $row);
if (is_object($oItem)) {
$my_item_id = $oItem->get_id();
//$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
@ -297,7 +296,7 @@ class learnpath {
// Get last viewing vars.
$lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
// This query should only return one or zero result.
$sql = "SELECT * FROM $lp_item_view_table
$sql = "SELECT status FROM $lp_item_view_table
WHERE c_id = $course_id AND lp_view_id = ".$this->lp_view_id." AND lp_item_id = ".$row['id']."
ORDER BY view_count DESC ";
if ($this->debug > 2) {
@ -2677,7 +2676,7 @@ class learnpath {
return false;
}
$tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
$sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
$sql = "SELECT id FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
$res = Database::query($sql);
while ($row = Database :: fetch_array($res)) {
$sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_id);

@ -71,7 +71,7 @@ class learnpathItem {
* @param integer User ID
* @return boolean True on success, false on failure
*/
public function __construct($id, $user_id = null, $course_id = null) {
public function __construct($id, $user_id = null, $course_id = null, $item_content = null) {
// Get items table.
if (!isset($user_id)) { $user_id = api_get_user_id(); }
if (self::debug > 0) { error_log('New LP - In learnpathItem constructor: '.$id.','.$user_id, 0); }
@ -85,15 +85,21 @@ class learnpathItem {
$items_table = Database::get_course_table(TABLE_LP_ITEM);
$this->course_id = api_get_course_int_id();
$id = (int) $id;
$sql = "SELECT * FROM $items_table WHERE c_id = $course_id AND id = $id";
//error_log('New LP - Creating item object from DB: '.$sql, 0);
$res = Database::query($sql);
if (Database::num_rows($res) < 1) {
$this->error = 'Could not find given learnpath item in learnpath_item table';
//error_log('New LP - '.$this->error, 0);
return false;
}
$row = Database::fetch_array($res);
if (empty($item_content)) {
$sql = "SELECT * FROM $items_table WHERE c_id = $course_id AND id = $id";
//error_log('New LP - Creating item object from DB: '.$sql, 0);
$res = Database::query($sql);
if (Database::num_rows($res) < 1) {
$this->error = 'Could not find given learnpath item in learnpath_item table';
//error_log('New LP - '.$this->error, 0);
return false;
}
$row = Database::fetch_array($res);
} else {
$row = $item_content;
}
$this->lp_id = $row['lp_id'];
$this->max_score = $row['max_score'];
$this->min_score = $row['min_score'];

Loading…
Cancel
Save