Browse Source

Eviter la clause Where 'in_rubrique IN (0)' dans la compilation du critere branches etc, c'est inutilement couteux.

2.0
Committo,Ergo:sum 15 years ago
parent
commit
528591f0fd
  1. 2
      ecrire/exec/rechercher.php
  2. 24
      ecrire/inc/rubriques.php
  3. 11
      ecrire/public/criteres.php

2
ecrire/exec/rechercher.php

@ -49,7 +49,7 @@ function exec_rechercher_args($id, $type, $exclus, $rac, $do)
if ($exclus) {
include_spip('inc/rubriques');
$where_exclus = " AND id_rubrique NOT IN (".calcul_branche($exclus).")";
$where_exclus = ' AND ' . calcul_branche_in($exclus, '', 'NOT');
} else $where_exclus = '';
$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus");

24
ecrire/inc/rubriques.php

@ -286,14 +286,13 @@ function calculer_langues_utilisees () {
// http://doc.spip.org/@calcul_generation
function calcul_generation ($generation) {
include_spip('base/abstract_sql');
$lesfils = array();
$result = sql_select(array('id_rubrique'),
array('spip_rubriques AS rubriques'),
array(sql_in('id_parent', $generation)));
$result = sql_select('id_rubrique',
'spip_rubriques',
sql_in('id_parent', $generation));
while ($row = sql_fetch($result))
$lesfils[] = $row['id_rubrique'];
return join(",",$lesfils);
return join(",", $lesfils);
}
// http://doc.spip.org/@calcul_branche
@ -308,6 +307,21 @@ function calcul_branche ($generation) {
}
}
function calcul_branche_in ($generation, $table='', $not='') {
if (!$generation) return ($not ? '0=1' : '0=0');
$branche = $generation;
while (1) {
$q = sql_select('id_rubrique', 'spip_rubriques', sql_in('id_parent', $generation));
$generation = '';
while ($r = sql_fetch($q))
$generation .= ',' .$r['id_rubrique'];
if (!$generation) break;
$branche .= $generation;
}
$cle = (!$table ? '' : ($table . '.')) . "id_rubrique";
return sql_in($cle, $branche, $not);
}
// Appelee lorsqu'un (ou plusieurs) article post-date arrive a terme
// ou est redate'
// Si $check, affecte le statut des rubriques concernees.

11
ecrire/public/criteres.php

@ -241,7 +241,6 @@ function critere_branche_dist($idb, &$boucles, $crit) {
$not = $crit->not;
$boucle = &$boucles[$idb];
$arg = calculer_argument_precedent($idb, 'id_rubrique', $boucles);
//Trouver une jointure
@ -251,13 +250,9 @@ function critere_branche_dist($idb, &$boucles, $crit) {
$cle = trouver_jointure_champ('id_rubrique', $boucle);
} else $cle = $boucle->id_table;
$c = "sql_in('" . $cle . ".id_rubrique', calcul_branche($arg), '')";
if ($crit->cond) $c = "($arg ? $c : 1)";
if ($not)
$boucle->where[]= array("'NOT'", $c);
else
$boucle->where[]= $c;
$c = "calcul_branche_in($arg, '$cle'" . ($not ? ", 'NOT'" : '') . ')';
$boucle->where[]= !$crit->cond ? $c :
("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") .')');
}
// {logo} liste les objets qui ont un logo

Loading…
Cancel
Save