From: Nicolas Boisselier Date: Mon, 29 Feb 2016 04:13:36 +0000 (+0000) Subject: tot optimisation X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=8204bb47783382a0e1fb76450750ecd4d0930af2;p=nb.git tot optimisation --- diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 7a0b0410..d116e3bd 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -685,42 +685,48 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } - // - // Tot - // - if ($select_count) { - $query = $this->db->conn->query('SELECT FOUND_ROWS()'); - - } elseif ($where) { - $sql_count = $sql; - $sql_count = preg_replace('/ (ORDER|LIMIT) .*?$/s','',$sql_count); - $sql_count = preg_replace('/^SELECT .*FROM/s','SELECT count(*) FROM ',$sql_count); - $query = $this->db->conn->query($sql_count); + if ($opt['is_html']) { + // + // Tot + // + if (true and !$where and !$limit) { + debug("Not using count(*)"); + $query = $this->db->conn->query("SELECT $count"); + + } elseif ($select_count) { + $query = $this->db->conn->query('SELECT FOUND_ROWS()'); + + } elseif ($where) { + $sql_count = $sql; + $sql_count = preg_replace('/ (ORDER|LIMIT) .*?$/s','',$sql_count); + $sql_count = preg_replace('/^SELECT .*FROM/s','SELECT count(*) FROM ',$sql_count); + $query = $this->db->conn->query($sql_count); - } else { - $query = $this->db->conn->query('SELECT count(*) FROM '.$this->sql_name()); + } else { + $query = $this->db->conn->query('SELECT count(*) FROM '.$this->sql_name()); - } + } - if (!$query) { - $err = $this->db->conn->errorInfo(); - $err[] = $sql; - err(join(' | ',$err)); - return $err[0]; - } + if (!$query) { + $err = $this->db->conn->errorInfo(); + $err[] = $sql; + err(join(' | ',$err)); + return $err[0]; + } - $tot = $query->fetch(PDO::FETCH_COLUMN); - $opt['tot'] = $tot; - #if (!$tot) return; + $tot = $query->fetch(PDO::FETCH_COLUMN); + $opt['tot'] = $tot; + #if (!$tot) return; - $opt['count'] = $count; - $opt['limit'] = $limit; - echo $this->{"rows_end_$format"}($opt); + $opt['count'] = $count; + $opt['limit'] = $limit; + echo $this->{"rows_end_$format"}(); - if ($opt['is_html']) echo '' - .PHP_EOL; + echo ''.PHP_EOL + ; + } $st->closeCursor(); @@ -780,21 +786,9 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. /*----------------------------------------------------------------- Yaml -----------------------------------------------------------------*/ - function rows_begin_yaml() { - return "---\n"; - } - - function rows_rec_yaml(&$row) { - $yaml = yaml_emit($row); - $yaml = preg_replace('/^---\n/','',$yaml); - $yaml = preg_replace('/\n\.\.\.$/','',$yaml); - $yaml = preg_replace('/^/m',' ',$yaml); - return '- '.trim($yaml)."\n"; - } - - function rows_end_yaml() { - return ''; - } + function rows_begin_yaml() { return "---\n"; } + function rows_rec_yaml(&$row) { return $this->yaml_encode($row); } + function rows_end_yaml() { return ''; } /*----------------------------------------------------------------- Xml diff --git a/lib/php/nb.php b/lib/php/nb.php index ca02fba1..c063a4dc 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -192,10 +192,10 @@ class nb { $yaml = yaml_emit($row); $yaml = preg_replace('/^---\n/','',$yaml); $yaml = preg_replace('/\n\.\.\.$/','',$yaml); - return "--- \n".trim($yaml)."\n"; - return trim($yaml)."\n"; - $yaml = preg_replace('/^/m',' ',$yaml); - return '- '.trim($yaml)."\n"; + $yaml = trim($yaml); + if ($yaml === "---") return '' ; + if (preg_match('/^---\s*$/m',$yaml)) return '' ; + return "--- \n$yaml\n"; } }