function getcount($condition) { $count = 0; if (isset($condition['token_noempty'])) { try { $count = DB::result_first(membersearch::makesql($condition, true)); } catch (Exception $e) { } } else { $count = DB::result_first(membersearch::makesql($condition, true)); } return intval($count); }
function cachesearch($condition, $start = 0, $limit = 20, $renew = false) { global $_G; $hash = membersearch::makehash($condition); $option = membersearch::getoption($hash); if (empty($option)) { $option = array('condition' => serialize($condition), 'hash' => $hash, 'users' => 0, 'updatetime' => 0); $optionid = DB::insert('common_member_stat_search', daddslashes($option), true); $option['optionid'] = intval($optionid); } $list = array(); if ($renew) { DB::query('DELETE FROM ' . DB::table('common_member_stat_searchcache') . " WHERE optionid='{$option['optionid']}'"); $sql = membersearch::makesql($condition); $query = DB::query($sql . ' LIMIT 5000'); $inserts = array(); $total = 0; $n = 1000; while ($value = DB::fetch($query)) { if ($limit > 0) { $list[] = intval($value['uid']); $limit--; } $inserts[] = "('{$option['optionid']}', '{$value['uid']}')"; $total++; if ($n > 0) { $n--; } else { DB::query('REPLACE INTO ' . DB::table('common_member_stat_searchcache') . '(optionid, uid) VALUES ' . implode(', ', $inserts)); $inserts = array(); $n = 100; } } if ($inserts) { DB::query('REPLACE INTO ' . DB::table('common_member_stat_searchcache') . '(optionid, uid) VALUES ' . implode(', ', $inserts)); } DB::update('common_member_stat_search', array('users' => $total, 'updatetime' => $_G['timestamp']), array('optionid' => $option['optionid'])); $option['users'] = $total; $option['updatetime'] = $_G['timestamp']; $_G['statsearch'][$hash] = $option; } else { $sql = 'SELECT uid FROM ' . DB::table('common_member_stat_searchcache') . " WHERE optionid='{$option['optionid']}' LIMIT {$start}, {$limit}"; $query = DB::query($sql); while ($value = DB::fetch($query)) { $list[] = intval($value['uid']); } } return $list; }