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

Changeset 225


Ignore:
Timestamp:
Sep 25, 2006, 4:27:54 PM (16 years ago)
Author:
ogawa
Message:

DBあしあとテーブルの件数を減らす機能

Location:
OpenPNE/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE/trunk/webapp/lib/db/read/ashiato.php

    r224 r225  
    5151    $sql = 'SELECT COUNT(*) FROM c_ashiato WHERE c_member_id_to = ?';
    5252    $params = array(intval($c_member_id));
    53     return db_get_one($sql, $params);
     53    $count = db_get_one($sql, $params);
     54
     55    $sql = 'SELECT ashiato_count_log FROM c_member WHERE c_member_id = ?';
     56    $params = array(intval($c_member_id));
     57    return $count + db_get_one($sql, $params);
    5458}
    5559
  • OpenPNE/trunk/webapp/lib/db/write/ashiato.php

    r102 r225  
    5454}
    5555
     56/**
     57 * Update c_member `ashiato_count_log` and delete c_ashiato rows
     58 *
     59 * @param int $limit
     60 */
     61function db_ashiato_update_log($limit = 30)
     62{
     63    $sql = 'SELECT c_member_id FROM c_member';
     64    $c_member_id_list = db_get_col($sql);
     65
     66    foreach ($c_member_id_list as $c_member_id) {
     67        $disp = p_h_ashiato_c_ashiato_list4c_member_id($c_member_id, $limit);
     68        if (!$disp) continue;
     69        $oldest_row = array_pop($disp);
     70
     71        $yesterday = date('Y-m-d 00:00:00', strtotime('-1 day'));
     72        $cutline = min($oldest_row['r_datetime'], $yesterday);
     73
     74        // delete c_ashiato rows
     75        $sql = 'DELETE FROM c_ashiato WHERE c_member_id_to = ? AND r_datetime < ?';
     76        $params = array(intval($c_member_id), $cutline);
     77        db_query($sql, $params);
     78        $affected_rows = db_affected_rows();var_dump($affected_rows);
     79
     80        // update c_member `ashiato_count_log`
     81        if ($affected_rows > 0) {
     82            $sql = 'UPDATE c_member SET ashiato_count_log = ashiato_count_log + ?' .
     83                   ' WHERE c_member_id = ?';
     84            $params = array(intval($affected_rows), intval($c_member_id));
     85            db_query($sql, $params);
     86        }
     87    }
     88}
     89
    5690?>
Note: See TracChangeset for help on using the changeset viewer.