mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-28 20:45:00 +03:00
Оптимизация контроля прочтения топика(REPLACE заменём на SELECT/UPDATE/INSERT дабы избавиться от медленного DELETE, при большом числе юзеров возможны тормоза)
This commit is contained in:
parent
62a829d8ff
commit
78cb76ca08
|
@ -682,17 +682,18 @@ class Topic extends Module {
|
|||
return $data;
|
||||
}
|
||||
/**
|
||||
* Обновляем дату прочтения топика, если читаем его первый раз то добавляем
|
||||
* Обновляем/устанавливаем дату прочтения топика, если читаем его первый раз то добавляем
|
||||
*
|
||||
* @param unknown_type $sTopicId
|
||||
* @param unknown_type $sUserId
|
||||
*/
|
||||
public function SetDateRead($sTopicId,$sUserId,$iCountComment) {
|
||||
$res=$this->oMapperTopic->SetDateRead($sTopicId,$sUserId,$iCountComment);
|
||||
if ($res==1 or $res==2) {
|
||||
return true;
|
||||
if ($this->GetDateRead($sTopicId,$sUserId)) {
|
||||
$this->oMapperTopic->UpdateDateRead($sTopicId,$sUserId,$iCountComment);
|
||||
} else {
|
||||
$this->oMapperTopic->AddDateRead($sTopicId,$sUserId,$iCountComment);
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Получаем дату прочтения топика юзером
|
||||
|
|
|
@ -1007,17 +1007,31 @@ class Mapper_Topic extends Mapper {
|
|||
return $aReturn;
|
||||
}
|
||||
|
||||
public function SetDateRead($sTopicId,$sUserId,$iCountComment) {
|
||||
public function UpdateDateRead($sTopicId,$sUserId,$iCountComment) {
|
||||
$sDate=date("Y-m-d H:i:s");
|
||||
$sql = "REPLACE ".DB_TABLE_TOPIC_READ."
|
||||
$sql = "UPDATE ".DB_TABLE_TOPIC_READ."
|
||||
SET
|
||||
comment_count_last = ? ,
|
||||
date_read = ? ,
|
||||
topic_id = ? ,
|
||||
date_read = ?
|
||||
WHERE
|
||||
topic_id = ?
|
||||
AND
|
||||
user_id = ?
|
||||
";
|
||||
return $this->oDb->query($sql,$iCountComment,$sDate,$sTopicId,$sUserId);
|
||||
}
|
||||
}
|
||||
|
||||
public function AddDateRead($sTopicId,$sUserId,$iCountComment) {
|
||||
$sDate=date("Y-m-d H:i:s");
|
||||
$sql = "INSERT INTO ".DB_TABLE_TOPIC_READ."
|
||||
SET
|
||||
comment_count_last = ? ,
|
||||
date_read = ? ,
|
||||
topic_id = ? ,
|
||||
user_id = ?
|
||||
";
|
||||
return $this->oDb->query($sql,$iCountComment,$sDate,$sTopicId,$sUserId);
|
||||
}
|
||||
|
||||
public function GetDateRead($sTopicId,$sUserId) {
|
||||
$sql = "SELECT
|
||||
|
|
Loading…
Reference in a new issue