1
0
Fork 0

Unused indexes removed, queries changed

This commit is contained in:
Michael Vogel 2016-07-26 22:10:13 +02:00
commit 4961fb3a45
9 changed files with 69 additions and 56 deletions

View file

@ -599,57 +599,64 @@ function posts_from_gcontact($a, $gcontact_id) {
return $o;
}
/**
* @brief Returns posts from a given contact
* @brief Returns posts from a given contact url
*
* @param App $a argv application class
* @param int $contact_id contact
* @param int $contact_url Contact URL
*
* @return string posts in HTML
*/
function posts_from_contact($a, $contact_id) {
function posts_from_contact_url($a, $contact_url) {
require_once('include/conversation.php');
$r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
if (!$r)
return false;
// There are no posts with "uid = 0" with connector networks
// This speeds up the query a lot
$r = q("SELECT `network`, `id` AS `author-id` FROM `contact`
WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0",
dbesc(normalise_link($contact_url)));
if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")))
$sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
else
$sql = "`item`.`uid` = %d";
$contact = $r[0];
$author_id = intval($r[0]["author-id"]);
if(get_config('system', 'old_pager')) {
if (get_config('system', 'old_pager')) {
$r = q("SELECT COUNT(*) AS `total` FROM `item`
WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')",
intval(local_user()),
dbesc(str_replace("https://", "http://", $contact["url"])),
dbesc(str_replace("http://", "https://", $contact["url"])));
WHERE `author-id` = %d and $sql",
intval($author_id),
intval(local_user()));
$a->set_pager_total($r[0]['total']);
}
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
/*
"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_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`.`id` DESC LIMIT %d, %d",
FROM `item` FORCE INDEX (`authorid_created`)
WHERE `item`.`author-id` = %d AND $sql
AND NOT `deleted` AND NOT `moderated` AND `visible`
*/
$r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql.
" ORDER BY `item`.`created` DESC LIMIT %d, %d",
intval($author_id),
intval(local_user()),
intval($contact_id),
dbesc(str_replace("https://", "http://", $contact["url"])),
dbesc(str_replace("http://", "https://", $contact["url"])),
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
$o .= conversation($a,$r,'community',false);
$o = conversation($a,$r,'community',false);
if(!get_config('system', 'old_pager'))
if(!get_config('system', 'old_pager')) {
$o .= alt_pager($a,count($r));
else
} else {
$o .= paginate($a);
}
return $o;
}

View file

@ -65,6 +65,7 @@ class dba {
$this->db = @new mysqli($server,$user,$pass,$db);
if(! mysqli_connect_errno()) {
$this->connected = true;
//mysqli_set_charset($this->db, 'utf8');
}
}
else {
@ -72,6 +73,7 @@ class dba {
$this->db = mysql_connect($server,$user,$pass);
if($this->db && mysql_select_db($db,$this->db)) {
$this->connected = true;
//mysql_set_charset('utf8', $this->db);
}
}
if(! $this->connected) {

View file

@ -852,19 +852,19 @@ function db_definition() {
"uid_created" => array("uid","created"),
"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"),
"uid_commented" => array("uid","commented"),
//"uid_received" => array("uid","received"),
//"uid_network_commented" => array("uid","network","commented"),
//"uid_commented" => array("uid","commented"),
"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"),
//"uid_contactid_created" => array("uid","contact-id","created"),
"gcontactid_uid_created" => array("gcontact-id","uid","created"),
"authorid_created" => array("author-id","created"),
"ownerid_created" => array("owner-id","created"),
"wall_body" => array("wall","body(6)"),
"uid_visible_moderated_created" => array("uid","visible","moderated","created"),
//"wall_body" => array("wall","body(6)"),
//"uid_visible_moderated_created" => array("uid","visible","moderated","created"),
"uid_uri" => array("uid","uri"),
"uid_wall_created" => array("uid","wall","created"),
"resource-id" => array("resource-id"),
@ -873,7 +873,8 @@ function db_definition() {
"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"),
"contactid_verb" => array("contact-id","verb"),
//"contactid_verb" => array("contact-id","verb"),
"contactid" => array("contact-id"),
"deleted_changed" => array("deleted","changed"),
"uid_wall_changed" => array("uid","wall","changed"),
"uid_eventid" => array("uid","event-id"),

View file

@ -476,9 +476,10 @@ function onepoll_run(&$argv, &$argc){
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
if(!x($datarray,'parent-uri') and $reply) {
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d ORDER BY `created` DESC LIMIT 1",
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d AND `network` = '%s' ORDER BY `created` DESC LIMIT 1",
dbesc(protect_sprintf($datarray['title'])),
intval($importer_uid));
intval($importer_uid),
dbesc(NETWORK_MAIL));
if(count($r))
$datarray['parent-uri'] = $r[0]['parent-uri'];
}