|
44楼提到的完整代码贴下。 require/updateforum.php- function updateforum($fid,$lastinfo='') {//TODO 慢查询
- global $db,$db_fcachenum,$todayTopicNum;
- $fm = $db->get_one("SELECT fup,type,password,allowvisit,f_type FROM pw_forums WHERE fid=".S::sqlEscape($fid));
- if ($fm['type'] != 'category') {
- $subtopics = $subrepliess = 0;
- $query = $db->query("SELECT fid FROM pw_forums WHERE fup=".S::sqlEscape($fid));
- while ($subinfo = $db->fetch_array($query)) {
- @extract($db->get_one("SELECT COUNT(*) AS subtopic,SUM( replies ) AS subreplies FROM pw_threads WHERE fid=".S::sqlEscape($subinfo['fid'])." AND ifcheck='1'"));
- $subtopics += $subtopic;
- $subrepliess += $subreplies;
- $query2 = $db->query("SELECT fid FROM pw_forums WHERE fup=".S::sqlEscape($subinfo['fid']));
- while ($subinfo2 = $db->fetch_array($query2)) {
- @extract($db->get_one("SELECT COUNT(*) AS subtopic,SUM( replies ) AS subreplies FROM pw_threads WHERE fid=".S::sqlEscape($subinfo2['fid'])." AND ifcheck='1'"));
- $subtopics += $subtopic;
- $subrepliess += $subreplies;
- }
- }
- $rs = $db->get_one("SELECT COUNT(*) AS topic,SUM( replies ) AS replies FROM pw_threads WHERE fid=".S::sqlEscape($fid)."AND ifcheck='1' AND topped<=3");
- $topic = $rs['topic'];
- $replies = $rs['replies'];
- $article = $topic + $replies + $subtopics + $subrepliess;
- if (!$lastinfo) {
- $lt = $db->get_one("SELECT tid,author,postdate,lastpost,lastposter,subject FROM pw_threads WHERE fid=".S::sqlEscape($fid)." AND specialsort=0 AND ifcheck=1 AND lastpost>0 ORDER BY lastpost DESC LIMIT 1");
- if ($lt['postdate'] == $lt['lastpost']) {
- $subject = addslashes(substrs($lt['subject'],26));
- } else {
- $subject = 'Re:'.addslashes(substrs($lt['subject'],26));
- }
- $author = addslashes($lt['lastposter']);
- $lastinfo = $lt['tid'] ? $subject."\t".$author."\t".$lt['lastpost']."\t"."read.php?tid=$lt[tid]&page=e#a" : '' ;
- }
- /**
- $db->update("UPDATE pw_forumdata"
- . " SET ".S::sqlSingle(array(
- 'topic' => $topic,
- 'article' => $article,
- 'subtopic' => $subtopics,
- 'lastpost' => $lastinfo
- ))
- . " WHERE fid=".S::sqlEscape($fid));
- **/
- pwQuery::update('pw_forumdata', 'fid=:fid', array($fid), array(
- 'topic' => $topic,
- 'article' => $article,
- 'subtopic' => $subtopics,
- 'lastpost' => $lastinfo
- ));
- $todayTopicNum && $db->update("UPDATE pw_forumdata SET tpost = tpost+$todayTopicNum WHERE fid = " . S::sqlEscape($fid));
- if ($fm['password'] != '' || $fm['allowvisit'] != '' || $fm['f_type'] == 'hidden') {
- $lastinfo = '';
- }
- delfcache($fid,$db_fcachenum);
- if ($fm['type'] == 'sub' || $fm['type'] == 'sub2') {
- updateforum($fm['fup'],$lastinfo);
- }
- }
- }
|