From bc9bf5aa612ecd16a21d531fd6c3f2c780840bc1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 11 May 2009 00:19:50 +0000 Subject: Avoid using ORM_MPTT::parents() in relative_path() so that we're not calling ORM just to get paths. This is a 10x performance increase. --- core/models/item.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'core/models') diff --git a/core/models/item.php b/core/models/item.php index ce48c4d4..5b9211be 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -248,12 +248,17 @@ class Item_Model extends ORM_MPTT { */ public function relative_path() { if (empty($this->relative_path)) { - foreach ($this->parents() as $parent) { - if ($parent->id > 1) { - $paths[] = $parent->name; - } + $paths = array(); + foreach (Database::instance() + ->select("name") + ->from("items") + ->where("`left` <= {$this->left}") + ->where("`right` >= {$this->right}") + ->where("id <> 1") + ->orderby("left", "ASC") + ->get() as $row) { + $paths[] = $row->name; } - $paths[] = $this->name; $this->relative_path = implode($paths, "/"); } return $this->relative_path; -- cgit v1.2.3