ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 10704


Ignore:
Timestamp:
Feb 9, 2009, 3:33:32 PM (11 years ago)
Author:
ogawa
Message:

#3620:adminからの画像削除時の高負荷SQLを改善

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE/branches/stable-2.12.x/webapp/modules/admin/lib/db_admin.php

    r10175 r10704  
    444444function db_admin_delete_c_image_link4image_filename($image_filename)
    445445{
    446     $_pos = strpos($image_filename, '_');
    447     $prefix = substr($image_filename, 0, $_pos);
     446    $parts = explode('_', $image_filename);
     447    $prefix = $parts[0];
    448448
    449449    if ($prefix == 'b') {
    450         $sql = 'DELETE FROM c_banner WHERE image_filename = ?';
    451         $params = array($image_filename);
     450        $pkey = (int)$parts[1];
     451
     452        $sql = 'DELETE FROM c_banner WHERE c_banner_id = ? AND image_filename = ?';
     453        $params = array($pkey, $image_filename);
    452454        db_query($sql, $params);
    453455    }
     
    455457    if ($prefix == 'c') {
    456458        $tbl = 'c_commu';
    457         _db_admin_empty_filename($tbl, $image_filename);
     459        $pkey = (int)$parts[1];
     460
     461        _db_admin_empty_filename($tbl, $image_filename, 'image_filename', $pkey);
    458462    }
    459463
    460464    if ($prefix == 't' || $prefix == 'tc') {
    461465        $tbl = 'c_commu_topic_comment';
    462         _db_admin_empty_filename($tbl, $image_filename, 'image_filename1');
    463         _db_admin_empty_filename($tbl, $image_filename, 'image_filename2');
    464         _db_admin_empty_filename($tbl, $image_filename, 'image_filename3');
     466        $pkey = (int)$parts[1];
     467        $number = (int)$parts[2];
     468
     469        _db_admin_empty_filename($tbl, $image_filename, 'image_filename'.$number, $pkey);
    465470    }
    466471
    467472    if ($prefix == 'd') {
    468473        $tbl = 'c_diary';
    469         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_1');
    470         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_2');
    471         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_3');
     474        $pkey = (int)$parts[1];
     475        $number = (int)$parts[2];
     476
     477        _db_admin_empty_filename($tbl, $image_filename, 'image_filename_'.$number, $pkey);
    472478    }
    473479
    474480    if ($prefix == 'dc') {
    475481        $tbl = 'c_diary_comment';
    476         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_1');
    477         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_2');
    478         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_3');
     482        $pkey = (int)$parts[1];
     483        $number = (int)$parts[2];
     484
     485        _db_admin_empty_filename($tbl, $image_filename, 'image_filename_'.$number, $pkey);
    479486    }
    480487
    481488    if ($prefix == 'm') {
    482489        $tbl = 'c_member';
    483         _db_admin_empty_filename($tbl, $image_filename);
    484         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_1');
    485         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_2');
    486         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_3');
     490        $pkey = (int)$parts[1];
     491
     492        _db_admin_empty_filename($tbl, $image_filename, 'image_filename', $pkey);
     493        _db_admin_empty_filename($tbl, $image_filename, 'image_filename_1', $pkey);
     494        _db_admin_empty_filename($tbl, $image_filename, 'image_filename_2', $pkey);
     495        _db_admin_empty_filename($tbl, $image_filename, 'image_filename_3', $pkey);
    487496    }
    488497
    489498    if ($prefix == 'ms') {
    490499        $tbl = 'c_message';
    491         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_1');
    492         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_2');
    493         _db_admin_empty_filename($tbl, $image_filename, 'image_filename_3');
    494     }
    495 
    496     if ($prefix = 'a') {
     500        $pkey = (int)$parts[1];
     501        $number = (int)$parts[2];
     502
     503        _db_admin_empty_filename($tbl, $image_filename, 'image_filename_'.$number, $pkey);
     504    }
     505
     506    if ($prefix == 'a') {
    497507        $tbl = 'c_album';
    498         _db_admin_empty_filename($tbl, $image_filename, 'album_cover_image');
    499 
    500         $sql = 'DELETE FROM c_album_image WHERE image_filename = ?';
    501         $params = array($image_filename);
     508        $pkey = (int)$parts[1];
     509
     510        _db_admin_empty_filename($tbl, $image_filename, 'album_cover_image', $pkey);
     511
     512        $sql = 'DELETE FROM c_album_image WHERE c_album_id = ? AND image_filename = ?';
     513        $params = array($pkey, $image_filename);
    502514        db_query($sql, $params);
    503515    }
    504516
    505     if ($prefix = 'biz') {
     517    if ($prefix == 'biz') {
    506518        $tbl = 'biz_group';
    507519        _db_admin_empty_filename($tbl, $image_filename);
     
    512524}
    513525
    514 function _db_admin_empty_filename($tbl, $image_filename, $column = 'image_filename')
     526function _db_admin_empty_filename($tbl, $image_filename, $column = 'image_filename', $pkey = null)
    515527{
    516528    $data = array(
    517529        db_escapeIdentifier($column) => '',
    518530    );
    519     $where = array(
    520         db_escapeIdentifier($column) => $image_filename,
    521     );
     531    if ($pkey) {
     532        $where[$tbl . '_id'] = (int)$pkey;
     533    }
     534    $where[db_escapeIdentifier($column)] = $image_filename;
     535
    522536    db_update(db_escapeIdentifier($tbl), $data, $where);
    523537}
Note: See TracChangeset for help on using the changeset viewer.