New indexes for the API

This commit is contained in:
Michael Vogel 2016-07-19 08:43:57 +02:00
parent 4f07dfb35a
commit 8bf7db06db
8 changed files with 24 additions and 17 deletions

View File

@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5-dev' ); define ( 'FRIENDICA_VERSION', '3.5-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1199 ); define ( 'DB_UPDATE_VERSION', 1200 );
/** /**
* @brief Constant with a HTML line break. * @brief Constant with a HTML line break.

View File

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 3.5-dev (Asparagus) -- 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_title` (`uid`,`title`),
INDEX `uid_thrparent` (`uid`,`thr-parent`), INDEX `uid_thrparent` (`uid`,`thr-parent`),
INDEX `uid_parenturi` (`uid`,`parent-uri`), INDEX `uid_parenturi` (`uid`,`parent-uri`),
INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
INDEX `gcontactid_uid_created` (`gcontact-id`,`uid`,`created`), INDEX `gcontactid_uid_created` (`gcontact-id`,`uid`,`created`),
INDEX `authorid_created` (`author-id`,`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 `uid_wall_created` (`uid`,`wall`,`created`),
INDEX `resource-id` (`resource-id`), INDEX `resource-id` (`resource-id`),
INDEX `uid_type` (`uid`,`type`), 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 `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_wall_parent_created` (`uid`,`wall`,`parent`,`created`),
INDEX `uid_type_changed` (`uid`,`type`,`changed`), INDEX `uid_type_changed` (`uid`,`type`,`changed`),

View File

@ -631,11 +631,11 @@ function posts_from_contact($a, $contact_id) {
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`author-name` AS `name`, `owner-avatar` AS `photo`, `author-name` AS `name`, `owner-avatar` AS `photo`,
`owner-link` AS `url`, `owner-avatar` AS `thumb` `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 WHERE `item`.`uid` = %d AND `contact-id` = %d
AND `author-link` IN ('%s', '%s') AND `author-link` IN ('%s', '%s')
AND NOT `deleted` AND NOT `moderated` AND `visible` 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(local_user()),
intval($contact_id), intval($contact_id),
dbesc(str_replace("https://", "http://", $contact["url"])), dbesc(str_replace("https://", "http://", $contact["url"])),

View File

@ -202,8 +202,8 @@
else { else {
// process normal login request // process normal login request
$r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) $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", 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(trim($user)), dbesc(trim($user)),
dbesc($encrypted) dbesc($encrypted)
@ -220,7 +220,9 @@
throw new UnauthorizedException("This API requires login"); 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); call_hooks('logged_in', $a->user);
@ -476,7 +478,7 @@
return False; return False;
} else { } else {
$user = $_SESSION['uid']; $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]['self']) {
if ($uinfo[0]['network'] == "")
$uinfo[0]['network'] = NETWORK_DFRN;
$usr = q("select * from user where uid = %d limit 1", $usr = q("select * from user where uid = %d limit 1",
intval(api_user()) intval(api_user())
); );
@ -1090,7 +1096,7 @@
AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s'))) AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
AND `i`.`id` = `item`.`parent` AND `i`.`id` = `item`.`parent`
AND `item`.`type`!='activity' $privacy_sql AND `item`.`type`!='activity' $privacy_sql
ORDER BY `item`.`created` DESC ORDER BY `item`.`id` DESC
LIMIT 1", LIMIT 1",
intval($user_info['cid']), intval($user_info['cid']),
intval(api_user()), intval(api_user()),
@ -1206,7 +1212,6 @@
*/ */
function api_users_show(&$a, $type){ function api_users_show(&$a, $type){
$user_info = api_get_user($a); $user_info = api_get_user($a);
$lastwall = q("SELECT `item`.* $lastwall = q("SELECT `item`.*
FROM `item` FROM `item`
INNER JOIN `contact` ON `contact`.`id`=`item`.`contact-id` AND `contact`.`uid` = `item`.`uid` 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 ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
AND `type`!='activity' AND `type`!='activity'
AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`='' 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", LIMIT 1",
intval(api_user()), intval(api_user()),
dbesc(ACTIVITY_POST), dbesc(ACTIVITY_POST),
@ -1506,7 +1511,7 @@
$sql_extra = ''; $sql_extra = '';
if ($conversation) if ($conversation)
$sql_extra .= " AND `item`.`parent` = %d ORDER BY `received` ASC "; $sql_extra .= " AND `item`.`parent` = %d ORDER BY `id` ASC ";
else else
$sql_extra .= " AND `item`.`id` = %d"; $sql_extra .= " AND `item`.`id` = %d";

View File

@ -858,6 +858,7 @@ function db_definition() {
"uid_title" => array("uid","title"), "uid_title" => array("uid","title"),
"uid_thrparent" => array("uid","thr-parent"), "uid_thrparent" => array("uid","thr-parent"),
"uid_parenturi" => array("uid","parent-uri"), "uid_parenturi" => array("uid","parent-uri"),
"uid_contactid_id" => array("uid","contact-id","id"),
"uid_contactid_created" => array("uid","contact-id","created"), "uid_contactid_created" => array("uid","contact-id","created"),
"gcontactid_uid_created" => array("gcontact-id","uid","created"), "gcontactid_uid_created" => array("gcontact-id","uid","created"),
"authorid_created" => array("author-id","created"), "authorid_created" => array("author-id","created"),
@ -868,7 +869,7 @@ function db_definition() {
"uid_wall_created" => array("uid","wall","created"), "uid_wall_created" => array("uid","wall","created"),
"resource-id" => array("resource-id"), "resource-id" => array("resource-id"),
"uid_type" => array("uid","type"), "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)"), "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_wall_parent_created" => array("uid","wall","parent","created"),
"uid_type_changed" => array("uid","type","changed"), "uid_type_changed" => array("uid","type","changed"),

View File

@ -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`) 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`)) AND ((`item`.`owner-link` IN ('%s', '%s') AND (`item`.`parent` = `item`.`id`))
OR (`item`.`author-link` IN ('%s', '%s'))) OR (`item`.`author-link` IN ('%s', '%s')))
ORDER BY `item`.`received` DESC ORDER BY `item`.`id` DESC
LIMIT 0, 300", LIMIT 0, 300",
intval($owner["uid"]), dbesc($check_date), dbesc(NETWORK_DFRN), intval($owner["uid"]), dbesc($check_date), dbesc(NETWORK_DFRN),
//dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS), //dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),

View File

@ -224,7 +224,7 @@ function content_content(&$a, $update = 0) {
$simple_update $simple_update
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra $sql_nets $sql_extra $sql_nets
ORDER BY `item`.`received` DESC $pager_sql ", ORDER BY `item`.`id` DESC $pager_sql ",
intval($_SESSION['uid']) intval($_SESSION['uid'])
); );

View File

@ -1,6 +1,6 @@
<?php <?php
define('UPDATE_VERSION' , 1199); define('UPDATE_VERSION' , 1200);
/** /**
* *