Re: svn: /phd/trunk/phpdotnet/phd/Reader/ Partial.php

From: Date: Sun, 24 Apr 2011 14:00:09 +0000
Subject: Re: svn: /phd/trunk/phpdotnet/phd/Reader/ Partial.php
References: 1 2 3  Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-8000@lists.php.net to get a copy of this message
On 24 April 2011 11:34, Hannes Magnusson <bjori@php.net> wrote: > On Sun, Apr 24, 2011 at 10:58, Richard Quadling <rquadling@gmail.com> wrote: >> On 24 April 2011 09:25, Hannes Magnusson <bjori@php.net> wrote: >>> bjori                                    Sun, 24 Apr 2011 08:25:29 >>> +0000 >>> >>> Revision: >>> http://svn.php.net/viewvc?view=revision&revision=310450 >>> >>> Log: >>> shave off few seconds when seeking for an chunk to render >>> >>> Changed paths: >>>    U   phd/trunk/phpdotnet/phd/Reader/Partial.php >>> >>> Modified: phd/trunk/phpdotnet/phd/Reader/Partial.php >>> =================================================================== >>> --- phd/trunk/phpdotnet/phd/Reader/Partial.php  2011-04-24 07:11:34 UTC (rev 310449) >>> +++ phd/trunk/phpdotnet/phd/Reader/Partial.php  2011-04-24 08:25:29 UTC (rev 310450) >>> @@ -6,6 +6,7 @@ >>>  { >>>     protected $partial = array(); >>>     protected $skip    = array(); >>> +    protected $parents = array(); >>> >>>     public function __construct() { >>>         parent::__construct(); >>> @@ -28,6 +29,22 @@ >>>         } else { >>>             throw new \Exception("Didn't get any IDs to seek"); >>>         } >>> +        $sqlite = new \SQLite3(Config::output_dir() . "index.sqlite"); >>> + >>> +        // Fetch all ancestors of the ids we should render >>> +        foreach($render_ids as $p => $v) { >>> +            do { >>> +                $id = $sqlite->escapeString($p); >>> +                $row = $sqlite->query("SELECT parent_id FROM ids WHERE >>> docbook_id = '$id'")->fetchArray(SQLITE3_ASSOC); >>> +                if ($row["parent_id"]) { >>> +                    $parents[] = $p = $row["parent_id"]; >>> +                    continue; >>> +                } >>> +                break; >>> +            } while(1); >>> +        } >>> + >>> +        $this->parents = $parents; >>>     } >>> >>>     public function read() { >>> @@ -92,6 +109,13 @@ >>>             } elseif (empty($this->partial)) { >>>                 return false; >>>             } else { >>> +                if ($id) { >>> +                    // If this id isn't one of our ancestors we can >>> jump >>> +                    // completely over it >>> +                    if (!in_array($id, $this->parents)) { >>> +                        parent::next(); >>> +                    } >>> +                } >>>                 $ignore = true; >>>             } >>>         } >> >> The approach being used here (the Adjacent Set Model) requires a query >> to be executed for each level until you run out of levels. >> >> For very large numbers of levels, there is a much more efficient >> mechanism, the Nested Set Model. >> >> >> http://dev.mysql.com/tech-resources/articles/hierarchical-data.html >> >> For any number of levels, a single query will return all the data. >> >> Is this something worth considering? > > No. Those queries (even in the worst case, 6*partial-id-count queries) > take a fraction of a nanosecond. > > Besides, if we want to go for a proper hierarcical data model on the > database level we need to store a lot more information, which will > increase the save and load time by more then it takes to run those 6 > queries. > Keeping in mind these queries are only executed during partial build.. > there is no way its worth adding more data to the db :) > > -Hannes > Ok. Context is everything. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.doc.cvs (#8000) next »