找回密码
 快速注册
搜索
查看: 66|回复: 3

热门的算法是什么?

[复制链接]

48

主题

992

回帖

1万

积分

积分
14981
QQ

显示全部楼层

Czhang271828 发表于 2022-6-17 11:18 |阅读模式
无钱佮歹看、无样佮歹生、无汉草佮无文采、无学历佮无能力、无高度无速度无力度共闲无代志。(闽南话)
口号:疼惜生命,远离内卷。

15

主题

958

回帖

1万

积分

积分
12454

显示全部楼层

色k 发表于 2022-6-17 11:49
母鸡呀
这名字我喜欢

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-6-17 17:02


任务时间表(crontab)文件储存的指令被crond守护进程激活,守护进程在后台运行,并每一分钟检查是否有定期的作业需要执行。这类作业一般称为cron jobs。
install/data/install_data.sql 第59行:
INSERT INTO pre_common_cron VALUES ('19','1','system','统计今日热帖','cron_todayheats_daily.php','1269746623','1269792000','-1','-1','0','0');
source/include/cron/cron_todayheats_daily.php 全部代码:
<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: cron_todayheats_daily.php 31913 2012-10-24 06:52:26Z zhengqingpeng $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$yesterday = strtotime(dgmdate(TIMESTAMP, 'Y-m-d'))-86400;
$data = $tids = $fids = $hotnum = array();
$daystr = dgmdate($yesterday, 'Ymd');
foreach(C::t('forum_thread')->fetch_all_for_guide('hot', 0, array(), $_G['setting']['heatthread']['guidelimit'], $yesterday, 0, 0) as $thread) {
	$data[$thread['tid']] = array(
			'cid' => 0,
			'fid' => $thread['fid'],
			'tid' => $thread['tid']
		);
	$fids[$thread['fid']] = array('fid' => $thread['fid'], 'dateline' => $daystr, 'hotnum' => 0);
	$tids[$thread['fid']][$thread['tid']] = $thread['tid'];
}
if($data) {
	$cids = C::t('forum_threadcalendar')->fetch_all_by_fid_dateline(array_keys($fids), $daystr);
	foreach($cids as $fid => $cinfo) {
		$hotnum[$cinfo['cid']] = count($tids[$fid]);
		foreach($tids[$fid] as $tid) {
			$data[$tid]['cid'] = $cinfo['cid'];
		}
		unset($fids[$fid]);
	}
	if($fids) {
		C::t('forum_threadcalendar')->insert_multiterm($fids);
		foreach(C::t('forum_threadcalendar')->fetch_all_by_fid_dateline(array_keys($fids), $daystr) as $fid => $cinfo) {
			$hotnum[$cinfo['cid']] = count($tids[$fid]);
			foreach($tids[$fid] as $tid) {
				$data[$tid]['cid'] = $cinfo['cid'];
			}
		}
	}
	C::t('forum_threadhot')->insert_multiterm($data);
	foreach($hotnum as $cid => $num) {
		C::t('forum_threadcalendar')->update($cid, array('hotnum' => $num));
	}
}

?>
Discuz X3 database table structure:
表名说明字段类型默认非空递增备注
forum_threadhot 热帖日历数据表 fid mediumint(8) unsigned 0 NO 版块ID

forum_threadhot

热帖日历数据表

tid

mediumint(8) unsigned

0

NO

主题ID


source/class/table/table_forum_threadcalendar.php 全部代码:
<?php
/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: table_forum_threadcalendar.php 31913 2012-10-24 06:52:26Z zhengqingpeng $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
class table_forum_threadcalendar extends discuz_table {

	public function __construct() {

		$this->_table = 'forum_threadcalendar';
		$this->_pk    = 'cid';

		parent::__construct();
	}

	public function fetch_by_fid_dateline($fid, $dateline = 0, $order = 'dateline', $sort = 'DESC') {
		$parameter = array($this->_table);
		$wherearr = array();
		$wheresql = '';
		if($fid) {
			$wherearr[] = 'fid=%d';
			$parameter[] = $fid;
		}
		if($dateline) {
			$wherearr[] = 'dateline=%d';
			$parameter[] = $dateline;
		}
		if($wherearr) {
			$wheresql = ' WHERE '.implode(' AND ', $wherearr);
		}
		return DB::fetch_first('SELECT * FROM %t '.$wheresql.' ORDER BY '.DB::order($order, $sort), $parameter, $this->_pk);
	}

	public function fetch_all_by_dateline($dateline) {
		$dateline = dintval($dateline);
		if($dateline) {
			return DB::fetch_all('SELECT * FROM %t WHERE dateline=%d', array($this->_table, $dateline), 'fid');
		} else {
			return array();
		}
	}

	public function fetch_all_by_fid_dateline($fids, $dateline = 0) {
		$parameter = array($this->_table);
		$wherearr = array();
		$wheresql = '';
		$fids = dintval($fids, true);
		if($fids) {
			$wherearr[] = is_array($fids) ? 'fid IN(%n)' : 'fid=%d';
			$parameter[] = $fids;
		}
		$dateline = dintval($dateline);
		if($dateline) {
			$wherearr[] = 'dateline=%d';
			$parameter[] = $dateline;
		}
		if($wherearr) {
			$wheresql = ' WHERE '.implode(' AND ', $wherearr);
		}
		return DB::fetch_all('SELECT * FROM %t '.$wheresql, $parameter, 'fid');
	}

	public function insert_multiterm($dataarr) {
		$allkey = array('fid', 'dateline', 'hotnum');
		$sql = array();
		foreach($dataarr as $key => $value) {
			if(is_array($value)) {
				$fid = dintval($value['fid']);
				$dateline = dintval($value['dateline']);
				$hotnum = dintval($value['hotnum']);
				$sql[] = "($fid, $dateline, $hotnum)";
			}
		}
		if($sql) {
			return DB::query('INSERT INTO '.DB::table($this->_table)." (`fid`, `dateline`, `hotnum`) VALUES ".implode(',', $sql), true);
		}
		return false;
	}
}

?>
install/data/install.sql 第2902行:
DROP TABLE IF EXISTS pre_forum_threadcalendar;
CREATE TABLE pre_forum_threadcalendar (
  cid mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  fid mediumint(8) unsigned NOT NULL DEFAULT '0',
  dateline int(10) unsigned NOT NULL DEFAULT '0',
  hotnum int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (cid),
  KEY fid (fid,dateline)
) TYPE=MyISAM;

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-6-17 17:37
BBS论坛项目相关-18:热帖排行模块
热帖排行

根据帖子是否加精,评论数,点赞数,收藏数以及发布时间等进行计算加分然后排名
log(精华分+评论数*10+点赞数*2+收藏数*2)+(发布时间-纪元)
用log让前期评论点赞等权重较重,后期影响较小。
为了效率较高,每次点赞评论等不立即进行算分,而是放入redis中进行缓存,之后定时进行计算。
设计一个帖子分数的key,当发生点赞评论等操作时就存入redis中。
redis中只是存储帖子分数发生变化的帖子id,所以使用redis的set存储,去重,防止重复计算。对帖子点赞,评论等行为,把帖子id放在redis。

原文链接:blog.csdn.net/hjukyjhg56/article/details/108063161

评分

参与人数 1威望 +1 收起 理由
Czhang271828 + 1

查看全部评分

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:39

Powered by Discuz!

× 快速回复 返回顶部 返回列表