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

From: Date: Sun, 24 Apr 2011 08:58:19 +0000
Subject: Re: svn: /phd/trunk/phpdotnet/phd/Reader/ Partial.php
References: 1  Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-7995@lists.php.net to get a copy of this message
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? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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