source code contribution for performance improvement

adrhc

Joined: 2013-07-31
Posts: 7
Posted: Sun, 2013-08-18 09:48

Hi, I implemented and tested on my Gallery 3.0.4 the following modifications in order to allow:

function parents() from ORM_MPTT.php
function _build_relative_caches() from Item.phpto

use the index items(type, left_ptr, right_ptr) otherwise you'll have a full scan on that huge items table despite ANY index you might have (enable, then check slow query log in mysql if you don't believe me).

function parents() {

return $this
->where("left_ptr", "<=", $this->left_ptr)
->where("right_ptr", ">=", $this->right_ptr)
->where("type", "=", "album")
->where("id", "<>", $this->id)
->order_by("left_ptr", "ASC")
->find_all();

}

private function _build_relative_caches() {
$names = array();
$slugs = array();
foreach (db::build()
->select(array("name", "slug"))
->from("items")
->where("left_ptr", "=", $this->left_ptr)
->where("right_ptr", "=", $this->right_ptr)
->where("type", "=", "photo")
->or_where("left_ptr", "<=", $this->left_ptr)
->where("right_ptr", ">=", $this->right_ptr)
->where("type", "=", "album")
->where("id", "<>", 1)
->order_by("left_ptr", "ASC")
->execute() as $row) {
// Don't encode the names segment
...
}

For my low resource Zyxel NSA310 this is huge improvement; I hope you'll see the value of these small changes,

BR,

Adrian