[perf]for 루프 조건의 count() 호출을 루프 밖으로 추출 (핵심 파일)
for ($i=0; $i<count(\$arr); $i++) 패턴은 매 반복마다 count()를 호출하여 불필요한 CPU 오버헤드를 발생시킴. 루프 전에 한 번만 count()를 계산하여 변수에 저장하는 고전적인 최적화. 적용 파일 (19개, 41곳): - lib/common.lib.php (8) - common.php (2) - lib/shop.lib.php (5) - lib/naverpay.lib.php (1) - lib/thumbnail.lib.php (2) - bbs/list.php (1), bbs/search.php (4), bbs/qalist.php (1), bbs/qawrite.php (1) - bbs/ajax.filter.php (1), bbs/write_update.php (4) - bbs/write_comment_update.php (1), bbs/memo_form_update.php (2) - bbs/new_delete.php (1), bbs/move_update.php (4) - shop/search.php (1), shop/orderform.sub.php (1) - mobile/shop/search.php (1), mobile/shop/orderform.sub.php (1) 부수 효과: - lib/shop.lib.php line 2115: 동일 루프 내 strstr($dlcomp, $company)를 strpos($dlcomp, $company) !== false 로 변경 (strstr 최적화의 일부) 제외: - theme/, skin/, plugin/ (사용자 커스터마이징/서드파티) - lib/PHPExcel/ (서드파티 라이브러리) - adm/ 및 shop/mail/ (관리자/드문 경로, 별도 후속 작업 여지) - 주석 처리된 코드 (bbs/delete.php:127, bbs/delete_all.php:143)
This commit is contained in:
1 parent
29e55de1fa
commit
a612e69d3e
19 files changed
+85
-43
No files matched your search
+8
-4
@@ -233,10 +233,12 @@ delete_cache_latest($bo_table);
|
||||
|
||||
if ($sw == 'move')
|
||||
{
|
||||
for ($i=0; $i<count($save); $i++)
|
||||
$save_cnt = count($save);
|
||||
for ($i=0; $i<$save_cnt; $i++)
|
||||
{
|
||||
if( isset($save[$i]['bf_file']) && $save[$i]['bf_file'] ){
|
||||
for ($k=0; $k<count($save[$i]['bf_file']); $k++) {
|
||||
$bf_file_cnt = count($save[$i]['bf_file']);
|
||||
for ($k=0; $k<$bf_file_cnt; $k++) {
|
||||
$del_file = run_replace('delete_file_path', clean_relative_paths($save[$i]['bf_file'][$k]), $save[$i]);
|
||||
|
||||
if ( is_file($del_file) && file_exists($del_file) ){
|
||||
@@ -248,7 +250,8 @@ if ($sw == 'move')
|
||||
}
|
||||
}
|
||||
|
||||
for ($k=0; $k<count($save[$i]['wr_contents']); $k++){
|
||||
$wr_contents_cnt = count($save[$i]['wr_contents']);
|
||||
for ($k=0; $k<$wr_contents_cnt; $k++){
|
||||
delete_editor_thumbnail($save[$i]['wr_contents'][$k]);
|
||||
}
|
||||
|
||||
@@ -262,7 +265,8 @@ if ($sw == 'move')
|
||||
$sql = " select bo_notice from {$g5['board_table']} where bo_table = '{$bo_table}' ";
|
||||
$row = sql_fetch($sql);
|
||||
$arr_notice = explode(',', $row['bo_notice']);
|
||||
for ($i=0; $i<count($arr_notice); $i++) {
|
||||
$arr_notice_cnt = count($arr_notice);
|
||||
for ($i=0; $i<$arr_notice_cnt; $i++) {
|
||||
$move_id = (int)$arr_notice[$i];
|
||||
// 게시판에 wr_id 가 있다면 이동한게 아니므로 bo_notice 에 다시 넣음
|
||||
$row2 = sql_fetch(" select count(*) as cnt from $write_table where wr_id = '{$move_id}' ");
|
||||
|
||||
Reference in new issue
Block a user