function post_create($arr, $fid) { global $conf, $time; $pid = post__create($arr); if (!$pid) { return $pid; } $tid = $arr['tid']; $uid = $arr['uid']; // 回帖 if ($tid > 0) { thread__update($tid, array('posts+' => 1, 'lastpid' => $pid, 'lastuid' => $uid, 'last_date' => $time)); $uid and user__update($uid, array('posts+' => 1)); runtime_set('posts+', 1); runtime_set('todayposts+', 1); forum__update($fid, array('todayposts+' => 1)); // 最新回复 thread_lastpid_create($tid, $pid); thread_tids_cache_delete_by_order($fid, 'lastpid'); } post_list_cache_delete($tid); // 更新板块信息。 thread_lastpid_cache_delete(); forum_list_cache_delete(); // 更新附件 $attachlist = attach_find_just_upload($uid); if ($attachlist) { foreach ($attachlist as $attach) { attach__update($attach['aid'], array('tid' => $tid, 'pid' => $pid)); } list($images, $files) = attach_images_files($attachlist); post__update($pid, array('images' => $images, 'files' => $files)); } return $pid; }
function cron_run($force = 0) { global $conf, $time, $forumlist, $runtime; $cron_1_last_date = runtime_get('cron_1_last_date'); $cron_2_last_date = runtime_get('cron_2_last_date'); $t = $time - $cron_1_last_date; if ($t > 300 || $force) { $lock = cache_get('cron_lock_1'); if ($lock === NULL) { cache_set('cron_lock_1', 1, 10); // 设置 10 秒超时 // 清理在线 online_gc(); runtime_set('cron_1_last_date', $time); cache_delete('cron_lock_1'); } } $t = $time - $cron_2_last_date; if ($t > 86400 || $force) { $lock = cache_get('cron_lock_2'); // 高并发下, mysql 机制实现的锁锁不住,但是没关系 if ($lock === NULL) { cache_set('cron_lock_2', 1, 10); // 设置 10 秒超时 // 每日统计清 0 runtime_set('todayposts', 0); runtime_set('todaythreads', 0); runtime_set('todayusers', 0); foreach ($forumlist as $fid => $forum) { forum__update($fid, array('todayposts' => 0, 'todaythreads' => 0)); } forum_list_cache_delete(); // 清理最新发帖,只保留 100 条。 thread_new_gc(); thread_lastpid_gc(); // 清理在线 online_gc(); // 清理临时附件 attach_gc(); // 清空每日 IP 限制 ipaccess_truncate(); // 清理游客喜欢限制 guest_agree_truncate(); list($y, $n, $d) = explode(' ', date('Y n j', $time)); // 0 点 $today = mktime(0, 0, 0, $n, $d, $y); // -8 hours runtime_set('cron_2_last_date', $today, TRUE); // 加到1天后 // 每日生成最新的 sitemap thread_new_sitemap(); // 往前推8个小时,尽量保证在前一天 table_day_cron($time - 8 * 3600); cache_delete('cron_lock_2'); } } }
function forum_update($fid, $arr) { $r = forum__update($fid, $arr); forum_list_cache_delete(); return $r; }
function thread_delete($tid) { global $conf; $thread = thread__read($tid); if (empty($thread)) { return TRUE; } $fid = $thread['fid']; $uid = $thread['uid']; $r = thread__delete($tid); if ($r === FALSE) { return FALSE; } // 删除所有回帖,同时更新 posts 统计数 $n = post_delete_by_tid($tid); // 删除我的主题 $uid and mythread_delete($uid, $tid); // 删除附件 // 更新统计 forum__update($fid, array('threads-' => 1)); user__update($uid, array('threads-' => 1)); // 删除 SEO URL thread_url_delete($tid); // 全站统计 runtime_set('threads-', 1); // 清除相关缓存 thread_tids_cache_delete($fid); forum_list_cache_delete(); // 最新和置顶也清理 thread_new_delete($tid); thread_top_delete($tid); thread_lastpid_delete($tid); thread_new_cache_delete(); thread_top_cache_delete(); thread_lastpid_cache_delete(); return $r; }