1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-05-20 17:58:24 +03:00

оптимизация индексов в БД

This commit is contained in:
Mzhelskiy Maxim 2010-03-28 19:40:51 +00:00
parent f2324ec7ad
commit 5e48b973ad
6 changed files with 100 additions and 20 deletions

View file

@ -170,11 +170,11 @@ class Mapper_Blog extends Mapper {
FROM
".Config::Get('db.table.blog_user')." as bu
WHERE
bu.user_id = ?d
bu.blog_id IN(?a)
AND
bu.blog_id IN(?a) ";
bu.user_id = ?d ";
$aBlogUsers=array();
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId)) {
if ($aRows=$this->oDb->select($sql,$aArrayId,$sUserId)) {
foreach ($aRows as $aUser) {
$aBlogUsers[]=Engine::GetEntity('Blog_BlogUser',$aUser);
}

View file

@ -17,28 +17,30 @@
class Mapper_Comment extends Mapper {
public function GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,$aExcludeTarget=array()) {
public function GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
$sql = "SELECT
comment_id
FROM
".Config::Get('db.table.comment')."
WHERE
target_type = ?
target_type = ?
AND
comment_date >= ?
AND
comment_rating >= 0
AND
comment_delete = 0
AND
comment_publish = 1
AND
comment_date >= ?
AND
comment_rating >= 0
{ AND target_id NOT IN(?a) }
{ AND target_parent_id NOT IN (?a) }
ORDER by comment_rating desc, comment_id desc
LIMIT 0, ?d ";
$aComments=array();
if ($aRows=$this->oDb->select(
$sql,$sTargetType, $sDate,
(is_array($aExcludeTarget)&&count($aExcludeTarget)) ? $aExcludeTarget : DBSIMPLE_SKIP,
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
$iLimit
)
) {
@ -330,11 +332,11 @@ class Mapper_Comment extends Mapper {
$sql = "
DELETE FROM ".Config::Get('db.table.comment')."
WHERE
target_type = ?
target_id IN (?a)
AND
target_id IN (?a)
target_type = ?
";
if ($this->oDb->query($sql,$sTargetType,$aTargetId)) {
if ($this->oDb->query($sql,$aTargetId,$sTargetType)) {
return true;
}
return false;

View file

@ -41,14 +41,14 @@ class Mapper_Favourite extends Mapper {
}
$sql = "SELECT *
FROM ".Config::Get('db.table.favourite')."
WHERE
WHERE
user_id = ?d
AND
target_id IN(?a)
AND
target_type = ?
AND
user_id = ?d";
target_type = ? ";
$aFavourites=array();
if ($aRows=$this->oDb->select($sql,$aArrayId,$sTargetType,$sUserId)) {
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId,$sTargetType)) {
foreach ($aRows as $aRow) {
$aFavourites[]=Engine::GetEntity('Favourite',$aRow);
}

View file

@ -130,4 +130,29 @@ ALTER TABLE `prefix_blog` CHANGE `blog_avatar` `blog_avatar` VARCHAR( 250 );
ALTER TABLE `prefix_comment` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_comment_online` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_topic` CHANGE `topic_tags` `topic_tags` VARCHAR( 500 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `prefix_topic` CHANGE `topic_tags` `topic_tags` VARCHAR( 500 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `prefix_comment` DROP INDEX `rating_date_id`;
ALTER TABLE `prefix_comment` DROP INDEX `topic_id`;
ALTER TABLE `prefix_comment` DROP INDEX `comment_delete`;
ALTER TABLE `prefix_comment` DROP INDEX `comment_date`;
ALTER TABLE `prefix_comment` ADD INDEX `type_date_rating` ( `target_type` , `comment_date` , `comment_rating` );
ALTER TABLE `prefix_comment` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_comment` ADD INDEX `type_delete_publish` ( `target_type` , `comment_delete` , `comment_publish` );
ALTER TABLE `prefix_comment` ADD INDEX `user_type` ( `user_id` , `target_type` );
ALTER TABLE `prefix_comment` ADD INDEX ( `target_parent_id` );
ALTER TABLE `prefix_comment` DROP INDEX `user_id`;
ALTER TABLE `prefix_comment_online` DROP INDEX `topic_id`;
ALTER TABLE `prefix_comment_online` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_comment_online` ADD INDEX `type_parent` ( `target_type` , `target_parent_id` );
ALTER TABLE `prefix_favourite` DROP INDEX `user_id`;
ALTER TABLE `prefix_favourite` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_friend` DROP INDEX `user_from`;
ALTER TABLE `prefix_notify_task` ADD INDEX ( `date_created` );

View file

@ -955,4 +955,30 @@ ALTER TABLE `prefix_user` ADD `user_date_topic_last` DATETIME AFTER `user_dat
ALTER TABLE `prefix_user` DROP `user_date_topic_last`;
ALTER TABLE `prefix_comment` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_comment_online` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_comment_online` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_comment` DROP INDEX `rating_date_id`;
ALTER TABLE `prefix_comment` DROP INDEX `topic_id`;
ALTER TABLE `prefix_comment` DROP INDEX `comment_delete`;
ALTER TABLE `prefix_comment` DROP INDEX `comment_date`;
ALTER TABLE `prefix_comment` ADD INDEX `type_date_rating` ( `target_type` , `comment_date` , `comment_rating` );
ALTER TABLE `prefix_comment` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_comment` ADD INDEX `type_delete_publish` ( `target_type` , `comment_delete` , `comment_publish` );
ALTER TABLE `prefix_comment` ADD INDEX `user_type` ( `user_id` , `target_type` );
ALTER TABLE `prefix_comment` ADD INDEX ( `target_parent_id` );
ALTER TABLE `prefix_comment` DROP INDEX `user_id`;
ALTER TABLE `prefix_comment_online` DROP INDEX `topic_id`;
ALTER TABLE `prefix_comment_online` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_comment_online` ADD INDEX `type_parent` ( `target_type` , `target_parent_id` );
ALTER TABLE `prefix_favourite` DROP INDEX `user_id`;
ALTER TABLE `prefix_favourite` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_friend` DROP INDEX `user_from`;
ALTER TABLE `prefix_notify_task` ADD INDEX ( `date_created` );

View file

@ -137,4 +137,31 @@ ALTER TABLE `prefix_user` DROP `user_date_topic_last`;
ALTER TABLE `prefix_comment` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_comment_online` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_topic` CHANGE `topic_tags` `topic_tags` VARCHAR( 500 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `prefix_topic` CHANGE `topic_tags` `topic_tags` VARCHAR( 500 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `prefix_comment` DROP INDEX `rating_date_id`;
ALTER TABLE `prefix_comment` DROP INDEX `topic_id`;
ALTER TABLE `prefix_comment` DROP INDEX `comment_delete`;
ALTER TABLE `prefix_comment` DROP INDEX `comment_date`;
ALTER TABLE `prefix_comment` ADD INDEX `type_date_rating` ( `target_type` , `comment_date` , `comment_rating` );
ALTER TABLE `prefix_comment` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_comment` ADD INDEX `type_delete_publish` ( `target_type` , `comment_delete` , `comment_publish` );
ALTER TABLE `prefix_comment` ADD INDEX `user_type` ( `user_id` , `target_type` );
ALTER TABLE `prefix_comment` ADD INDEX ( `target_parent_id` );
ALTER TABLE `prefix_comment` DROP INDEX `user_id`;
ALTER TABLE `prefix_comment_online` DROP INDEX `topic_id`;
ALTER TABLE `prefix_comment_online` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_comment_online` ADD INDEX `type_parent` ( `target_type` , `target_parent_id` );
ALTER TABLE `prefix_favourite` DROP INDEX `user_id`;
ALTER TABLE `prefix_favourite` ADD INDEX `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_friend` DROP INDEX `user_from`;
ALTER TABLE `prefix_notify_task` ADD INDEX ( `date_created` );