Commit 846fdc5a authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Don't fetch artefact from db unnecessarily when saving a block



Change-Id: Ib1f744067b3bee1b5908739f363bb3dd35a12444
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent f6101a74
...@@ -432,6 +432,7 @@ class BlockInstance { ...@@ -432,6 +432,7 @@ class BlockInstance {
private $canmoveup; private $canmoveup;
private $canmovedown; private $canmovedown;
private $maxorderincolumn; private $maxorderincolumn;
private $artefacts = array();
public function __construct($id=0, $data=null) { public function __construct($id=0, $data=null) {
if (!empty($id)) { if (!empty($id)) {
...@@ -1074,6 +1075,10 @@ class BlockInstance { ...@@ -1074,6 +1075,10 @@ class BlockInstance {
* Get an artefact instance, checking republish permissions * Get an artefact instance, checking republish permissions
*/ */
public function get_artefact_instance($id) { public function get_artefact_instance($id) {
if (isset($this->artefacts[$id])) {
return $this->artefacts[$id];
}
require_once(get_config('docroot') . 'artefact/lib.php'); require_once(get_config('docroot') . 'artefact/lib.php');
$a = artefact_instance_from_id($id); $a = artefact_instance_from_id($id);
$viewowner = $this->get_view()->get('owner'); $viewowner = $this->get_view()->get('owner');
...@@ -1087,7 +1092,8 @@ class BlockInstance { ...@@ -1087,7 +1092,8 @@ class BlockInstance {
throw new ArtefactNotFoundException(get_string('artefactnotpublishable', 'mahara', $id, $this->get_view()->get('id'))); throw new ArtefactNotFoundException(get_string('artefactnotpublishable', 'mahara', $id, $this->get_view()->get('id')));
} }
} }
return $a;
return $this->artefacts[$id] = $a;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment