From fc66a86dc538f072e279dd56110abb0735e1dfce Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 6 Jun 2016 22:57:27 +0200 Subject: [PATCH] Some optimized sql queries --- boot.php | 2 +- database.sql | 4 ++-- include/dbstructure.php | 2 +- include/group.php | 2 +- mod/profile.php | 2 +- update.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/boot.php b/boot.php index adfeeb415f..99229972eb 100644 --- a/boot.php +++ b/boot.php @@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1195 ); +define ( 'DB_UPDATE_VERSION', 1196 ); /** * @brief Constant with a HTML line break. diff --git a/database.sql b/database.sql index 07fb65b96d..8269a8bba0 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 3.5-dev (Asparagus) --- DB_UPDATE_VERSION 1195 +-- DB_UPDATE_VERSION 1196 -- ------------------------------------------ @@ -511,7 +511,7 @@ CREATE TABLE IF NOT EXISTS `item` ( INDEX `extid` (`extid`), INDEX `uid_id` (`uid`,`id`), INDEX `uid_created` (`uid`,`created`), - INDEX `uid_unseen` (`uid`,`unseen`), + INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`), INDEX `uid_network_received` (`uid`,`network`,`received`), INDEX `uid_received` (`uid`,`received`), INDEX `uid_network_commented` (`uid`,`network`,`commented`), diff --git a/include/dbstructure.php b/include/dbstructure.php index e6064b3971..f89a3ff926 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -847,7 +847,7 @@ function db_definition() { "extid" => array("extid"), "uid_id" => array("uid","id"), "uid_created" => array("uid","created"), - "uid_unseen" => array("uid","unseen"), + "uid_unseen_contactid" => array("uid","unseen","contact-id"), "uid_network_received" => array("uid","network","received"), "uid_received" => array("uid","received"), "uid_network_commented" => array("uid","network","commented"), diff --git a/include/group.php b/include/group.php index 00b66ad586..53c0b78d84 100644 --- a/include/group.php +++ b/include/group.php @@ -366,7 +366,7 @@ function groups_containing($uid,$c) { function groups_count_unseen() { $r = q("SELECT `group`.`id`, `group`.`name`, - (SELECT COUNT(*) FROM `item` + (SELECT COUNT(*) FROM `item` FORCE INDEX (`uid_unseen_contactid`) WHERE `uid` = %d AND `unseen` AND `contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `group_member`.`gid` = `group`.`id` AND `group_member`.`uid` = %d)) AS `count` diff --git a/mod/profile.php b/mod/profile.php index 26bd395230..58e3a16072 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -284,7 +284,7 @@ function profile_content(&$a, $update = 0) { $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `thread`.`uid` AS `contact-uid` - FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` + FROM `thread` FORCE INDEX (`uid_created`) INNER JOIN `item` ON `item`.`id` = `thread`.`iid` $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0 diff --git a/update.php b/update.php index b74edf7bbd..1189ac4a91 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@