1
1
Fork 0

Merge pull request #3007 from annando/1607-performance

Some more performance stuff
This commit is contained in:
Tobias Diekershoff 2016-12-12 07:04:16 +01:00 committed by GitHub
commit 352b168e2d
6 changed files with 38 additions and 52 deletions

View file

@ -666,57 +666,55 @@ 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 string $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`,
`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",
$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

@ -475,9 +475,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'];
}

View file

@ -894,16 +894,7 @@ function contact_posts($a, $contact_id) {
$o .= $tab_str;
$r = q("SELECT `id` FROM `item` WHERE `contact-id` = %d LIMIT 1", intval($contact_id));
if ($r)
$o .= posts_from_contact($a, $contact_id);
elseif ($contact["url"]) {
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
dbesc(normalise_link($contact["url"])));
if ($r[0]["id"] <> 0)
$o .= posts_from_gcontact($a, $r[0]["id"]);
}
$o .= posts_from_contact_url($a, $contact["url"]);
return $o;
}

View file

@ -137,13 +137,13 @@ function follow_content(&$a) {
$a->page['aside'] = "";
profile_load($a, "", 0, get_contact_details_by_url($ret["url"]));
// Show last public posts
if ($gcontact_id <> 0) {
$o .= replace_macros(get_markup_template('section_title.tpl'),
array('$title' => t('Status Messages and Posts')
));
$o .= posts_from_gcontact($a, $gcontact_id);
// Show last public posts
$o .= posts_from_contact_url($a, $ret["url"]);
}
return $o;

View file

@ -442,8 +442,8 @@ function network_content(&$a, $update = 0) {
// desired.
$sql_post_table = "";
$sql_options = (($star) ? " and starred = 1 " : '');
$sql_options .= (($bmark) ? " and bookmark = 1 " : '');
$sql_options = (($star) ? " AND `thread`.`starred` " : '');
$sql_options .= (($bmark) ? " AND `thread`.`bookmark` " : '');
$sql_extra = $sql_options;
$sql_extra2 = "";
$sql_extra3 = "";
@ -579,8 +579,8 @@ function network_content(&$a, $update = 0) {
$sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
else
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
$sql_order = "`item`.`received`";
$order_mode = "received";
$sql_order = "`item`.`id`";
$order_mode = "id";
}
}
if(strlen($file)) {
@ -598,8 +598,7 @@ function network_content(&$a, $update = 0) {
// only setup pagination on initial page view
$pager_sql = '';
}
else {
} else {
if(get_config('system', 'old_pager')) {
$r = qu("SELECT COUNT(*) AS `total`
FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = $sql_table.`contact-id`
@ -638,7 +637,7 @@ function network_content(&$a, $update = 0) {
$simple_update = (($update) ? " AND `item`.`unseen` " : '');
if ($sql_order == "")
$sql_order = "`item`.`received`";
$sql_order = "`item`.`id`";
// "New Item View" - show all items unthreaded in reverse created date order
$items = qu("SELECT %s FROM $sql_table $sql_post_table %s

View file

@ -217,10 +217,7 @@ function nodeinfo_cron() {
set_config('nodeinfo','active_users_monthly', $active_users_monthly);
}
$posts = qu("SELECT COUNT(*) AS `local_posts` FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `contact`.`self` and `item`.`id` = `item`.`parent` AND left(body, 6) != '[share' AND `item`.`network` IN ('%s', '%s', '%s')",
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
$posts = qu("SELECT COUNT(*) AS local_posts FROM `thread` WHERE `thread`.`wall` AND `thread`.`uid` != 0");
if (!is_array($posts))
$local_posts = -1;