function getThreadsFromForums($fids, $imgMode = false, $pageNo = 1, $excludeTids = array()) { if ($pageNo <= 0) { $pageNo = 1; } $pageSize = 20; $start = ($pageNo - 1) * $pageSize; sort($fids); $oldFids = $fids; //获得当前用户组允许访问的板块列表 $fInfos = getGroupFroumInfo(); $_fids = array_keys($fInfos); //和想要访问的板块做交集,得到真正允许访问的板块列表 $fids = array_intersect($fids, $_fids); if (empty($fids)) { return array('page_no' => $pageNo, 'page_size' => $pageSize, 'total' => 0, 'total_page' => 0, 'thread_list' => array()); } global $_G, $expireTime; sort($fids); //排序,减少缓存数量 //当前用户组在指定板块下的摘要KEY $cacheKey = 'bigapp_fids_tinfos_' . $_G['groupid'] . '_' . implode(', ', $oldFids); $md5Key = md5($cacheKey); $detailCacheKey = ''; true === BIGAPP_DEV && runlog('bigapp', 'bigapp fids thread info summary key: ' . $cacheKey . ', md5 key: ' . $md5Key . ', group id: ' . $_G['groupid']); loadcache($md5Key); $ret = array('page_no' => $pageNo, 'page_size' => $pageSize, 'total' => 0, 'total_page' => 0, 'thread_list' => array()); if (!isset($_G['cache'][$md5Key]) || empty($_G['cache'][$md5Key]) || TIMESTAMP - $_G['cache'][$md5Key]['expiration'] > $expireTime) { if (isset($_G['cache'][$md5Key])) { clearFidsList($oldFids, $_G['groupid']); } //获取版块中所有的主题ID $tInfo = array(); $sql = 'SELECT SQL_CALC_FOUND_ROWS tid, fid, posttableid, typeid, readperm, author, authorid, subject, dateline, lastpost, lastposter, views, replies, digest, attachment, heats, icon FROM ' . DB::table('forum_thread') . ' WHERE fid IN (' . implode(', ', $fids) . ') AND displayorder >= 0 ORDER BY dateline DESC LIMIT ' . $start . ', ' . $pageSize; true === BIGAPP_DEV && runlog('bigapp', "summary info does not exist or expired, get thread info from db [ start: {$start}, page size: {$pageSize}, page no: {$pageNo}, sql: {$sql} ]"); $query = DB::query($sql); while ($tmp = DB::fetch($query)) { $tInfo[] = $tmp; } $sql = 'select FOUND_ROWS() AS total'; true === BIGAPP_DEV && runlog('bigapp', 'get total [ sql: ' . $sql . ' ]'); $query = DB::query($sql); $total = 0; while ($tmp = DB::fetch($query)) { $total = $tmp['total']; break; } $sumary = array('fids' => $oldFids, 'total' => $total, 'page_size' => $pageSize, 'page' => intval(($total - 1) / $pageSize) + 1); true === BIGAPP_DEV && runlog('bigapp', 'save summary info [ cache key: ' . $cacheKey . ', md5 key: ' . $md5Key . ', value: ' . json_encode($sumary) . ' ]'); savecache($md5Key, array('variable' => $sumary, 'expiration' => TIMESTAMP)); //缓存摘要信息 //接下来缓存当前用户组在指定块下、指定页面上的信息 $subKeyTemp = 'bigapp_fids_tinfos_' . $_G['groupid'] . '_' . implode(', ', $oldFids); $subKey = $subKeyTemp . '_' . ($pageNo - 1); $md5SubKey = md5($subKey); $ret['total'] = $total; $ret['total_page'] = intval(($total - 1) / $pageSize) + 1; if (!empty($tInfo)) { //当前页非空,缓存本页数据 extendThreadsInfo($tInfo, $fInfos); getDetails($tInfo); savecache($md5SubKey, array('variable' => $tInfo, 'expiration' => TIMESTAMP)); //缓存子KEY信息 true === BIGAPP_DEV && runlog('bigapp', "such page is not empty, save them to cache [ page: {$pageNo}, key: {$subKey}, md5 key: {$md5SubKey} ]"); $ret['thread_list'] = $tInfo; } else { true === BIGAPP_DEV && runlog('bigapp', "such page is empty, ignore [ page: {$pageNo}, key: {$subKey}, md5 key: {$md5SubKey} ]"); //do nothing $ret['thread_list'] = array(); } } else { true === BIGAPP_DEV && runlog('bigapp', 'summary info already exist, get thread info from cache [ key: ' . $cacheKey . ', summary key: ' . $md5Key . ' ]'); $sumVar = $_G['cache'][$md5Key]['variable']; $ret['total'] = $sumVar['total']; $ret['total_page'] = $sumVar['page']; if ($pageNo <= $sumVar['page']) { $subKey = 'bigapp_fids_tinfos_' . $_G['groupid'] . '_' . implode(', ', $oldFids) . '_' . ($pageNo - 1); $md5SubKey = md5($subKey); loadcache($md5SubKey); if (!isset($_G['cache'][$md5SubKey]) || empty($_G['cache'][$md5SubKey])) { true === BIGAPP_DEV && runlog('bigapp', "such page does not in cache, try to create it [ page no: {$pageNo}, sub key: {$subKey}, md5 key: {$md5SubKey} ]"); $sql = 'SELECT tid, fid, posttableid, typeid, readperm, author, authorid, subject, dateline, lastpost, lastposter, views, replies, digest, attachment, heats, icon FROM ' . DB::table('forum_thread') . ' WHERE fid IN (' . implode(', ', $fids) . ') AND displayorder >= 0 ORDER BY dateline DESC LIMIT ' . $start . ', ' . $pageSize; true === BIGAPP_DEV && runlog('bigapp', "get sub info from db [ page no: {$pageNo}, sub key: {$subKey}, md5 key: {$md5SubKey}, sql: {$sql} ]"); $query = DB::query($sql); while ($tmp = DB::fetch($query)) { $tInfo[] = $tmp; } if (!empty($tInfo)) { extendThreadsInfo($tInfo, $fInfos); getDetails($tInfo); savecache($md5SubKey, array('variable' => $tInfo, 'expiration' => TIMESTAMP)); //缓存子KEY信息 true === BIGAPP_DEV && runlog('bigapp', "create such page succ, save them to cache [ page no: {$pageNo}, sub key: {$subKey}, md5 key: {$md5SubKey}, num of result: " . count($tInfo) . " ]"); $ret['thread_list'] = $tInfo; } else { true === BIGAPP_DEV && runlog('bigapp', "create such page failed, empty [ page no: {$pageNo}, sub key: {$subKey}, md5 key: {$md5SubKey}, page no: " . count($tInfo) . " ]"); //do nothing } } else { true === BIGAPP_DEV && runlog('bigapp', 'such page already exists in cache, get thread info from cache [ page no: ' . $pageNo . ', sub key ' . $subKey . ', md5 key: ' . $md5SubKey . ' ]'); $ret['thread_list'] = $_G['cache'][$md5SubKey]['variable']; } } else { true === BIGAPP_DEV && runlog('bigapp', "invalid page, return empty array [ page no: {$pageNo}, total page: " . $sumVar['page'] . " ]"); //do nothing } } $tmp = $ret['thread_list']; $ret['thread_list'] = array(); if (!empty($excludeTids)) { foreach ($tmp as $_t) { if (in_array($_t['tid'], $excludeTids)) { true === BIGAPP_DEV && runlog('bigapp', 'tid is in exclude array, ignore [ tid: ' . $_t['tid'] . ', ext ids: ' . json_encode($excludeTids) . ' ]'); continue; } if (!$imgMode) { $_t['message_abstract'] = ''; $_t['attachment_urls'] = array(); } $ret['thread_list'][] = $_t; } } else { foreach ($tmp as $_t) { if (!$imgMode) { $_t['message_abstract'] = ''; $_t['attachment_urls'] = array(); } $ret['thread_list'][] = $_t; } } true === BIGAPP_DEV && runlog('bigapp', 'get thread info finished [ count: ' . count($ret) . ', page: ' . $pageNo . ' ]'); return $ret; }
$ret['count'] = $articles['total']; if (intval($articles['total_page']) > intval($page)) { $ret['need_more'] = '1'; } } //读取板块下的帖子列表 if (is_array($fids) && !empty($fids)) { //比对版块设置是否发生变化,清楚上一次的cache $content_setting_fids = C::t('common_setting')->fetch('content_setting_fids', true); if (false === $content_setting_fids[0]) { $oldfids = array(); } else { $oldfids = $content_setting_fids; } if ($oldfids !== $fids && !empty($oldfids)) { clearFidsList($oldfids); } $settings = array('content_setting_fids' => $fids); C::t('common_setting')->update_batch($settings); $threadInfos = getThreadsFromForums($fids, $ispic_mode, $page, $all_tids); //取forum name if (isset($threadInfos['thread_list'])) { $sql = "SELECT name FROM " . DB::table('forum_forum') . " where fid="; foreach ($threadInfos['thread_list'] as $key => &$thread) { $name = ""; if (isset($thread['fid'])) { $query = DB::query($sql . $thread['fid']); $tmp = DB::fetch($query); if (isset($tmp['name'])) { $name = $tmp['name']; }