From 8bf7db06dbd76f63af4ac9f0c84a32ceb20b8119 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 19 Jul 2016 08:43:57 +0200 Subject: [PATCH] New indexes for the API --- boot.php | 2 +- database.sql | 5 +++-- include/Contact.php | 4 ++-- include/api.php | 21 +++++++++++++-------- include/dbstructure.php | 3 ++- include/ostatus.php | 2 +- mod/content.php | 2 +- update.php | 2 +- 8 files changed, 24 insertions(+), 17 deletions(-) diff --git a/boot.php b/boot.php index 298010dd0..8a92835e6 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', 1199 ); +define ( 'DB_UPDATE_VERSION', 1200 ); /** * @brief Constant with a HTML line break. diff --git a/database.sql b/database.sql index 2b55a896f..b27f69c40 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 3.5-dev (Asparagus) --- DB_UPDATE_VERSION 1199 +-- DB_UPDATE_VERSION 1200 -- ------------------------------------------ @@ -522,6 +522,7 @@ CREATE TABLE IF NOT EXISTS `item` ( INDEX `uid_title` (`uid`,`title`), INDEX `uid_thrparent` (`uid`,`thr-parent`), INDEX `uid_parenturi` (`uid`,`parent-uri`), + INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), INDEX `gcontactid_uid_created` (`gcontact-id`,`uid`,`created`), INDEX `authorid_created` (`author-id`,`created`), @@ -532,7 +533,7 @@ CREATE TABLE IF NOT EXISTS `item` ( INDEX `uid_wall_created` (`uid`,`wall`,`created`), INDEX `resource-id` (`resource-id`), INDEX `uid_type` (`uid`,`type`), - INDEX `uid_starred` (`uid`,`starred`), + INDEX `uid_starred_id` (`uid`,`starred`,`id`), INDEX `contactid_allowcid_allowpid_denycid_denygid` (`contact-id`,`allow_cid`(10),`allow_gid`(10),`deny_cid`(10),`deny_gid`(10)), INDEX `uid_wall_parent_created` (`uid`,`wall`,`parent`,`created`), INDEX `uid_type_changed` (`uid`,`type`,`changed`), diff --git a/include/Contact.php b/include/Contact.php index 10005d3e3..9d69a81a4 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -631,11 +631,11 @@ function posts_from_contact($a, $contact_id) { $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, `author-name` AS `name`, `owner-avatar` AS `photo`, `owner-link` AS `url`, `owner-avatar` AS `thumb` - FROM `item` FORCE INDEX (`uid_contactid_created`) + FROM `item` FORCE INDEX (`uid_contactid_id`) WHERE `item`.`uid` = %d AND `contact-id` = %d AND `author-link` IN ('%s', '%s') AND NOT `deleted` AND NOT `moderated` AND `visible` - ORDER BY `item`.`created` DESC LIMIT %d, %d", + ORDER BY `item`.`id` DESC LIMIT %d, %d", intval(local_user()), intval($contact_id), dbesc(str_replace("https://", "http://", $contact["url"])), diff --git a/include/api.php b/include/api.php index ff2d083cc..af0fa6008 100644 --- a/include/api.php +++ b/include/api.php @@ -202,8 +202,8 @@ else { // process normal login request - $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) - AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1", + $r = q("SELECT * FROM `user` WHERE (`email` = '%s' OR `nickname` = '%s') + AND `password` = '%s' AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified` LIMIT 1", dbesc(trim($user)), dbesc(trim($user)), dbesc($encrypted) @@ -220,7 +220,9 @@ throw new UnauthorizedException("This API requires login"); } - authenticate_success($record); $_SESSION["allow_api"] = true; + authenticate_success($record); + + $_SESSION["allow_api"] = true; call_hooks('logged_in', $a->user); @@ -476,7 +478,7 @@ return False; } else { $user = $_SESSION['uid']; - $extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` = 1 "; + $extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` "; } } @@ -548,6 +550,10 @@ } if($uinfo[0]['self']) { + + if ($uinfo[0]['network'] == "") + $uinfo[0]['network'] = NETWORK_DFRN; + $usr = q("select * from user where uid = %d limit 1", intval(api_user()) ); @@ -1090,7 +1096,7 @@ AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s'))) AND `i`.`id` = `item`.`parent` AND `item`.`type`!='activity' $privacy_sql - ORDER BY `item`.`created` DESC + ORDER BY `item`.`id` DESC LIMIT 1", intval($user_info['cid']), intval(api_user()), @@ -1206,7 +1212,6 @@ */ function api_users_show(&$a, $type){ $user_info = api_get_user($a); - $lastwall = q("SELECT `item`.* FROM `item` INNER JOIN `contact` ON `contact`.`id`=`item`.`contact-id` AND `contact`.`uid` = `item`.`uid` @@ -1214,7 +1219,7 @@ AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s'))) AND `type`!='activity' AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`='' - ORDER BY `created` DESC + ORDER BY `id` DESC LIMIT 1", intval(api_user()), dbesc(ACTIVITY_POST), @@ -1506,7 +1511,7 @@ $sql_extra = ''; if ($conversation) - $sql_extra .= " AND `item`.`parent` = %d ORDER BY `received` ASC "; + $sql_extra .= " AND `item`.`parent` = %d ORDER BY `id` ASC "; else $sql_extra .= " AND `item`.`id` = %d"; diff --git a/include/dbstructure.php b/include/dbstructure.php index 10e1e0e62..bd35d0974 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -858,6 +858,7 @@ function db_definition() { "uid_title" => array("uid","title"), "uid_thrparent" => array("uid","thr-parent"), "uid_parenturi" => array("uid","parent-uri"), + "uid_contactid_id" => array("uid","contact-id","id"), "uid_contactid_created" => array("uid","contact-id","created"), "gcontactid_uid_created" => array("gcontact-id","uid","created"), "authorid_created" => array("author-id","created"), @@ -868,7 +869,7 @@ function db_definition() { "uid_wall_created" => array("uid","wall","created"), "resource-id" => array("resource-id"), "uid_type" => array("uid","type"), - "uid_starred" => array("uid","starred"), + "uid_starred_id" => array("uid","starred", "id"), "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), "uid_wall_parent_created" => array("uid","wall","parent","created"), "uid_type_changed" => array("uid","type","changed"), diff --git a/include/ostatus.php b/include/ostatus.php index 7ac26846d..ec53141dc 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1971,7 +1971,7 @@ class ostatus { OR (`item`.`network` = '%s' AND ((`thread`.`network` IN ('%s', '%s')) OR (`thritem`.`network` IN ('%s', '%s')))) AND `thread`.`mention`) AND ((`item`.`owner-link` IN ('%s', '%s') AND (`item`.`parent` = `item`.`id`)) OR (`item`.`author-link` IN ('%s', '%s'))) - ORDER BY `item`.`received` DESC + ORDER BY `item`.`id` DESC LIMIT 0, 300", intval($owner["uid"]), dbesc($check_date), dbesc(NETWORK_DFRN), //dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS), diff --git a/mod/content.php b/mod/content.php index 54d499d40..c4b1f2f68 100644 --- a/mod/content.php +++ b/mod/content.php @@ -224,7 +224,7 @@ function content_content(&$a, $update = 0) { $simple_update AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra $sql_nets - ORDER BY `item`.`received` DESC $pager_sql ", + ORDER BY `item`.`id` DESC $pager_sql ", intval($_SESSION['uid']) ); diff --git a/update.php b/update.php index 41f238e91..8a8d93b1b 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@