By: zeflex
Date: 2011-10-04
Time: 17:28
|
Re: MergeBlock ralenti mon appli
Re salut,
En fait effectivement j'ai d'autres blocs où pour traiter une quantité de donnée définie, mon temps d'affichage accroit drastiquement ... Je te mets ici le contenu entier de la page php et juste après les temps donnés en sortie ... Je sais plus où donner de la tête ...
PHP :
<?php
include_once('../common.php');
include_once('../../fonctions.php');
$start_time = microtime_float();
function db_query($query) {
global $count_query;
$count_query++;
return mysql_query($query);
}
include_once('../../connect.php');
if ( isset($_GET['action']) && !empty($_GET['title_id']) ) {
check_read_only('titles');
function mass_del($varname,$tablename,$fieldname) {
$table = str_replace('|','',explode('||',$varname));
foreach( $table AS $key=>$value ) {
db_query("DELETE FROM $tablename WHERE `$fieldname` = $value");
}
}
$title_id = intval($_GET['title_id']);
$sql = db_query("SELECT * FROM titles WHERE title_id = $title_id");
$row = mysql_fetch_array($sql);
$categories = $row['categories'];
$original_languages = $row['origin_country'];
mass_del($original_languages,'languages','lang_id');
db_query("DELETE FROM titles_formats WHERE title_id = $title_id");
db_query("DELETE FROM availabilities WHERE title_id = $title_id");
db_query("DELETE FROM sales WHERE title_id = $title_id");
db_query("DELETE FROM external_links WHERE title_id = $title_id");
db_query("DELETE FROM titles WHERE title_id = $title_id");
mysql_close();
echo '<script type="text/javascript">$("#tr'.$title_id.'").fadeOut();</script>';
exit();
}
$pagename = 'Titles';
tbs_rbypage(); tbs_top_links();
if ( !empty($_POST) ) {
$error = '';
$query = 'SELECT A.*,B.lang_en AS original_lang_en,C.studioname AS studioname FROM titles AS A
LEFT JOIN languages AS B ON B.lang_id = A.language
LEFT JOIN studios AS C ON C.studio_id = A.studio
WHERE ';
foreach($_POST AS $key=>$value) {
$$key = mysql_real_escape_string(trim($value));
if ( $key == 'format_id' && !empty($value) ) {
$results = array();
$sub_sql = db_query("SELECT title_id FROM titles_formats WHERE format = $value");
if ( !mysql_num_rows($sub_sql) ) {
$error = 'No results founded';
}
while( $sub_row = mysql_fetch_array($sub_sql) ) {
$query.= "title_id = ".$sub_row['title_id']." OR ";
}
$query = substr($query,0,strlen($query)-3)."AND ";
}
if ( empty($error) && !empty($$key) && $key != 'submit' ) {
if ( $key == 'cat_id' )
$key = 'categories';
if ( $key == 'categories' )
$query.= $key.' LIKE \'%|'.$cat_id.'|%\' AND ';
elseif ( $key == 'from' )
$query.= 'production_year >= '.$from.' AND ';
elseif ( $key == 'to' )
$query.= 'production_year <= '.$to.' AND ';
elseif ( $key == 'studio_id' )
$query.= $key.' = '.$$key.' AND ';
elseif ( $key == 'volume' )
$query.= $key.' = '.$$key.' AND ';
elseif ( $key == 'keyword' )
$query.= 'keywords_fr LIKE \'%'.$$key.'%\' OR keywords_en LIKE \'%'.$$key.'%\' AND ';
elseif ( $key != 'format_id' )
$query.= $key.' LIKE \'%'.$$key.'%\' AND ';
}
}
$query = substr($query,0,strlen($query)-5);
$query.= 'ORDER BY '.$orderby.' '.$desc.' LIMIT '.$start.','.$results_by_page;
$TBS->MergeBlock('pagination',array());
if ( strlen($query) == 217 ) {
$query = $initial_query;
$TBS->MergeBlock('pagination','num',array('min'=>1,'max'=>$nb_pages));
}
} else {
// $TBS->MergeBlock('pagination','num',array('min'=>1,'max'=>$nb_pages));
}
$sql = db_query("SELECT count(title_id) AS total FROM titles");
$row = mysql_fetch_array($sql);
$total = $row['total'];
$nb_pages = ceil($total/$results_by_page);
if ( isset($_GET['orderby']) )
$orderby = mysql_real_escape_string($_GET['orderby']);
else
$orderby = 'title';
if ( isset($_GET['orderdesc']) )
$desc = 'DESC ';
else
$desc = '';
$results_by_page = 100;
$query = $initial_query = 'SELECT A.title_id,A.title_id_htaccess,A.title,A.img_url,A.production_year,B.lang_en AS original_lang_en,C.studioname AS studioname,E.format_en FROM titles AS A
LEFT JOIN languages AS B ON B.lang_id = A.language
LEFT JOIN studios AS C ON C.studio_id = A.studio
LEFT JOIN titles_formats AS D ON D.title_id = A.title_id
RIGHT JOIN formats AS E ON E.format_id = D.format
ORDER BY '.$orderby.' '.$desc.'
LIMIT '.$start.','.$results_by_page;
if ( $orderby == 'studio' )
$query = 'SELECT A.studioname AS studioname,B.title_id,B.title_id_htaccess,B.title,B.img_url,B.production_year,C.lang_en AS original_lang_en FROM studios AS A
RIGHT JOIN titles AS B ON B.studio = A.studio_id
LEFT JOIN languages AS C ON C.lang_id = B.language
ORDER BY '.$orderby.' '.$desc.'
LIMIT '.$start.','.$results_by_page;
$sql = db_query($query);
$cat_array = $languages = $formats = array();
// Making concordance for categories
$sql_cat = db_query("SELECT * FROM categories");
while ($row_cat = mysql_fetch_array($sql_cat)) {
$cat_array[$row_cat['cat_id']] = $row_cat['cat_en'];
}
$cat_display = array();
while ( $row = mysql_fetch_array($sql)) {
$title_id = $row['title_id'];
// Making concordance for categories
$categories = str_replace('|','',explode('||',$row['categories']));
$cat_name = '';
foreach($categories AS $key=>$val) {
if ( isset($cat_array[$val]) )
$cat_name.= $cat_array[$val].'<br/>';
}
$cat_name = substr($cat_name,0,-5);
array_push($cat_display,$cat_name);
//\\ MULTIPLES FORMATS AND LANGUAGES !
// \\ MULTIPLES FORMATS AND LANGUAGES !
// \\ MULTIPLES FORMATS AND LANGUAGES !
// \\ MULTIPLES FORMATS AND LANGUAGES !
// !!! \\ MULTIPLES FORMATS AND LANGUAGES !
// \\ MULTIPLES FORMATS AND LANGUAGES !
//____________\\ MULTIPLES FORMATS AND LANGUAGES !
// Making concordance for formats
// $formats_string = '';
// $sql_formats = db_query("SELECT B.format_en FROM titles_formats AS A LEFT JOIN formats AS B ON B.format_id = A.format WHERE A.title_id = $title_id");
// while($row_formats = mysql_fetch_array($sql_formats)) {
// $formats_string.= $row_formats['format_en'].'<br/>';
// }
// $format_string = substr($formats_string,0,-5);
// array_push($formats,$formats_string);
// Making concordance for languages
// $lang_name = '';
// $sql_languages = db_query("SELECT B.lang_en FROM titles_formats AS A LEFT JOIN languages AS B ON B.lang_id = A.language WHERE A.title_id = $title_id");
// while ($row_languages = mysql_fetch_array($sql_languages)) {
// $lang_name.= $row_languages['lang_en'].'<br/>';
// }
// $lang_name = substr($lang_name,0,-5);
// array_push($languages,$lang_name);
// Making concordance for formats
$formats_string = '';
$langs_string = '';
$sql_formats = db_query("SELECT B.format_en,C.lang_en FROM titles_formats AS A LEFT JOIN formats AS B ON B.format_id = A.format
LEFT JOIN languages AS C ON C.lang_id = A.language WHERE A.title_id = $title_id");
while($row_formats = mysql_fetch_array($sql_formats)) {
$formats_string.= $row_formats['format_en'].'<br/>';
$langs_string.= $row_formats['lang_en'].'<br/>';
}
$format_string = substr($formats_string,0,-5);
$lang_string = substr($langs_string,0,-5);
array_push($formats,$formats_string);
array_push($languages,$lang_string);
// Making concordance for languages
// $lang_name = '';
// $sql_languages = db_query("SELECT B.lang_en FROM titles_formats AS A LEFT JOIN languages AS B ON B.lang_id = A.language WHERE A.title_id = $title_id");
// while ($row_languages = mysql_fetch_array($sql_languages)) {
// $lang_name.= $row_languages['lang_en'].'<br/>';
// }
// $lang_name = substr($lang_name,0,-5);
// array_push($languages,$lang_name);
}
$timing = microtime_float();
echo $timing = "<br/>nb query : $count_query | timing = ".($timing-$start_time);
$TBS->MergeBlock('titles','mysql',$query);
$timing = microtime_float();
echo $timing = "<br/>nb query : $count_query | timing = ".($timing-$start_time);
$TBS->MergeBlock('categories','array',$cat_display);
// echo "<br/><pre>".print_r($cat_display)."</pre>";
$timing = microtime_float();
echo $timing = "<br/>nb query : $count_query | timing = ".($timing-$start_time);
$TBS->MergeBlock('formats','array',$formats);
// echo "<br/><pre>".print_r($formats)."</pre>";
$timing = microtime_float();
echo $timing = "<br/>nb query : $count_query | timing = ".($timing-$start_time);
$TBS->MergeBlock('langs','array',$languages);
// echo "<br/><pre>".print_r($languages)."</pre>";
$timing = microtime_float();
echo $timing = "<br/>nb query : $count_query | timing = ".($timing-$start_time);
exit();
$txtfields = array('Keyword'=>'keyword','Title'=>'title','Cast'=>'cast','# Volume'=>'volume');
$TBS->MergeBlock('blk11',$txtfields);
$TBS->MergeBlock('formats_s','mysql','SELECT * FROM formats ORDER BY format_en');
$TBS->MergeBlock('categories_s','mysql','SELECT * FROM categories ORDER BY cat_en');
$TBS->MergeBlock('studios_s','mysql','SELECT * FROM studios ORDER BY studioname');
$txtfields = array('From'=>'from','To'=>'to');
$TBS->MergeBlock('blk13',$txtfields);
$radiofields = array('titles'=>"",'Titles'=>"",'Data Import'=>"",'Report'=>"",'Admin'=>"");
$TBS->MergeBlock('blk2',$radiofields);
$timing = microtime_float();
echo $timing = "<br/>nb query : $count_query | timing = ".($timing-$start_time);
exit();
$TBS->MergeField('timing',$timing);
$TBS->Show();
?>
|
En sortie :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ndd/www/vvs/admin/pages/titles.php on line 181
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ndd/www/vvs/admin/pages/titles.php on line 181
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ndd/www/vvs/admin/pages/titles.php on line 181
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ndd/www/vvs/admin/pages/titles.php on line 181
nb query : 103 | timing = 1.51571106911
nb query : 103 | timing = 1.89339399338
nb query : 103 | timing = 3.30427908897
nb query : 103 | timing = 4.4575510025
nb query : 103 | timing = 6.50980901718
|
Ne pas tenir compte des premiers warning. Une idée pour améliorer la sauce ... ?
|
By: Skrol29
Date: 2011-10-05
Time: 17:47
|
Re: MergeBlock ralenti mon appli
Salut,
> Je ne peux pas passer plus de temps à faire divers tests pour essayer de comprendre par moi-même
Ha-là-là, mais c'est un support TBS ici, pas du crowdsourcing.
Voici tout de même un équivalent de ton bout de template sur le bloc "pagination", mais ultra-rapide.
HTML :
Pages : [pagination.#]
<span class="current">[pagination.val;block=span+span;when [pagination.val]=[special.current_page]]</span>
<span>[pagination.val;ope=mod:20,mok:0;magnet=span]<br><br></span>
<a href="?start=[pagination.val]&results_by_page=[special.results_by_page][special.orderby; if [val] != ''; then '&orderby=[val]'; else '']">[pagination.val;block=a+span;default]</a>
<span>[pagination.val;ope=mod:20,mok:0;magnet=span]<br><br></span>
|
Se fusionne avec le PHP suivant:
// fusion préalable des variables incluses dans le bloc
$tbs->MergeField('special', array(
'current_page'=> $current_page,
'orderby' => $orderby,
'results_by_page' =>$results_by_page,
));
// fusion du bloc
$tbs->MergeBlock('pagination', 'num', array('min'=>1,'max'=>$nb_pages));
|
|