- Improved speed due to forced indexes when showing items.

- Possibility to setup a hostname
This commit is contained in:
Michael Vogel 2013-09-15 10:40:58 +02:00
parent 159a7bda85
commit d5ae5ecedd
8 changed files with 41 additions and 38 deletions

View File

@ -289,7 +289,7 @@ define ( 'GRAVITY_COMMENT', 6);
*/ */
function startup() { function startup() {
error_reporting(E_ERROR | E_WARNING | E_PARSE); error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_time_limit(0); set_time_limit(0);
@ -389,7 +389,7 @@ if(! class_exists('App')) {
'stylesheet' => '', 'stylesheet' => '',
'template_engine' => 'smarty3', 'template_engine' => 'smarty3',
); );
// array of registered template engines ('name'=>'class name') // array of registered template engines ('name'=>'class name')
public $template_engines = array(); public $template_engines = array();
// array of instanced template engines ('name'=>'instance') // array of instanced template engines ('name'=>'instance')
@ -420,6 +420,9 @@ if(! class_exists('App')) {
global $default_timezone, $argv, $argc; global $default_timezone, $argv, $argc;
if (file_exists(".htpreconfig.php"))
@include(".htpreconfig.php");
$this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC'); $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
date_default_timezone_set($this->timezone); date_default_timezone_set($this->timezone);
@ -453,7 +456,7 @@ if(! class_exists('App')) {
if(x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) if(x($_SERVER,'HTTPS') && $_SERVER['HTTPS'])
$this->scheme = 'https'; $this->scheme = 'https';
elseif(x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) elseif(x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443))
$this->scheme = 'https'; $this->scheme = 'https';
if(x($_SERVER,'SERVER_NAME')) { if(x($_SERVER,'SERVER_NAME')) {
$this->hostname = $_SERVER['SERVER_NAME']; $this->hostname = $_SERVER['SERVER_NAME'];
@ -478,13 +481,17 @@ if(! class_exists('App')) {
if(isset($path) && strlen($path) && ($path != $this->path)) if(isset($path) && strlen($path) && ($path != $this->path))
$this->path = $path; $this->path = $path;
} }
if ($hostname != "")
$this->hostname = $hostname;
if (is_array($argv) && $argc>1 && substr(end($argv), 0, 4)=="http" ) { if (is_array($argv) && $argc>1 && substr(end($argv), 0, 4)=="http" ) {
$this->set_baseurl(array_pop($argv) ); $this->set_baseurl(array_pop($argv) );
$argc --; $argc --;
} }
set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path()); set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path());
if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") { if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
$this->query_string = substr($_SERVER['QUERY_STRING'],2); $this->query_string = substr($_SERVER['QUERY_STRING'],2);
// removing trailing / - maybe a nginx problem // removing trailing / - maybe a nginx problem
@ -550,7 +557,7 @@ if(! class_exists('App')) {
$mobile_detect = new Mobile_Detect(); $mobile_detect = new Mobile_Detect();
$this->is_mobile = $mobile_detect->isMobile(); $this->is_mobile = $mobile_detect->isMobile();
$this->is_tablet = $mobile_detect->isTablet(); $this->is_tablet = $mobile_detect->isTablet();
/** /**
* register template engines * register template engines
*/ */
@ -560,7 +567,7 @@ if(! class_exists('App')) {
$this->register_template_engine($k); $this->register_template_engine($k);
} }
} }
} }
function get_basepath() { function get_basepath() {
@ -640,7 +647,7 @@ if(! class_exists('App')) {
$this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0); $this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage']; $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
} }
function set_pager_page($n) { function set_pager_page($n) {
$this->pager['page'] = $n; $this->pager['page'] = $n;
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage']; $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
@ -773,7 +780,7 @@ if(! class_exists('App')) {
$template_engine = $this->theme['template_engine']; $template_engine = $this->theme['template_engine'];
} }
} }
if (isset($this->template_engines[$template_engine])){ if (isset($this->template_engines[$template_engine])){
if(isset($this->template_engine_instance[$template_engine])){ if(isset($this->template_engine_instance[$template_engine])){
return $this->template_engine_instance[$template_engine]; return $this->template_engine_instance[$template_engine];
@ -784,7 +791,7 @@ if(! class_exists('App')) {
return $obj; return $obj;
} }
} }
echo "template engine <tt>$template_engine</tt> is not registered!\n"; killme(); echo "template engine <tt>$template_engine</tt> is not registered!\n"; killme();
} }
@ -827,6 +834,7 @@ if(! class_exists('App')) {
//$this->performance["markstart"] -= microtime(true) - $this->performance["marktime"]; //$this->performance["markstart"] -= microtime(true) - $this->performance["marktime"];
$this->performance["markstart"] = microtime(true) - $this->performance["markstart"] - $this->performance["marktime"]; $this->performance["markstart"] = microtime(true) - $this->performance["markstart"] - $this->performance["marktime"];
} }
} }
} }
@ -1008,7 +1016,7 @@ if(! function_exists('update_db')) {
)); ));
$subject=sprintf(t('Update Error at %s'), $a->get_baseurl()); $subject=sprintf(t('Update Error at %s'), $a->get_baseurl());
require_once('include/email.php'); require_once('include/email.php');
$subject = email_header_encode($subject,'UTF-8'); $subject = email_header_encode($subject,'UTF-8');
mail($a->config['admin_email'], $subject, $email_msg, mail($a->config['admin_email'], $subject, $email_msg,
'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n" 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n"
@ -1020,7 +1028,7 @@ if(! function_exists('update_db')) {
else { else {
set_config('database','update_' . $x, 'success'); set_config('database','update_' . $x, 'success');
set_config('system','build', $x + 1); set_config('system','build', $x + 1);
} }
} }
} }
} }
@ -1288,7 +1296,7 @@ if(! function_exists('profile_load')) {
$user = q("select uid from user where nickname = '%s' limit 1", $user = q("select uid from user where nickname = '%s' limit 1",
dbesc($nickname) dbesc($nickname)
); );
if(! ($user && count($user))) { if(! ($user && count($user))) {
logger('profile error: ' . $a->query_string, LOGGER_DEBUG); logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
notice( t('Requested account is not available.') . EOL ); notice( t('Requested account is not available.') . EOL );
@ -1310,7 +1318,7 @@ if(! function_exists('profile_load')) {
} }
$r = null; $r = null;
if($profile) { if($profile) {
$profile_int = intval($profile); $profile_int = intval($profile);
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile` $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
@ -1334,7 +1342,7 @@ if(! function_exists('profile_load')) {
$a->error = 404; $a->error = 404;
return; return;
} }
// fetch user tags if this isn't the default profile // fetch user tags if this isn't the default profile
if(! $r[0]['is-default']) { if(! $r[0]['is-default']) {

View File

@ -487,7 +487,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$alike = array(); $alike = array();
$dlike = array(); $dlike = array();
// array with html for each thread (parent+comments) // array with html for each thread (parent+comments)
$threads = array(); $threads = array();
$threadsid = -1; $threadsid = -1;
@ -516,7 +515,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
if($blocked) if($blocked)
continue; continue;
} }
$threadsid++; $threadsid++;
@ -697,7 +696,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$threads[$threadsid]['items'] = array($arr['output']); $threads[$threadsid]['items'] = array($arr['output']);
} }
} }
else else
{ {
@ -719,7 +717,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
if($arr_blocked) { if($arr_blocked) {
$blocked = false; $blocked = false;
foreach($arr_blocked as $b) { foreach($arr_blocked as $b) {
if($b && link_compare($item['author-link'],$b)) { if($b && link_compare($item['author-link'],$b)) {
$blocked = true; $blocked = true;
break; break;
@ -728,7 +726,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
if($blocked) if($blocked)
continue; continue;
} }
// Can we put this after the visibility check? // Can we put this after the visibility check?
@ -754,6 +752,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
} }
$threads = $conv->get_template_data($alike, $dlike); $threads = $conv->get_template_data($alike, $dlike);
if(!$threads) { if(!$threads) {
logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
$threads = array(); $threads = array();

View File

@ -93,6 +93,8 @@ class dba {
$stamp2 = microtime(true); $stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1); $duration = (float)($stamp2-$stamp1);
$a->save_timestamp($stamp1, "database");
if(x($a->config,'system') && x($a->config['system'],'db_log')) { if(x($a->config,'system') && x($a->config['system'],'db_log')) {
if (($duration > $a->config["system"]["db_loglimit"])) { if (($duration > $a->config["system"]["db_loglimit"])) {
$duration = round($duration, 3); $duration = round($duration, 3);
@ -168,7 +170,7 @@ class dba {
} }
} }
$a->save_timestamp($stamp1, "database"); //$a->save_timestamp($stamp1, "database");
if($this->debug) if($this->debug)
logger('dba: ' . printable(print_r($r, true))); logger('dba: ' . printable(print_r($r, true)));

View File

@ -104,12 +104,12 @@ if((x($_GET,'zrl')) && (!$install && !$maintenance)) {
* For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header. * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.
* Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it
* this way. There's a PHP flag to link the headers because by default this will over-write any other * this way. There's a PHP flag to link the headers because by default this will over-write any other
* link header. * link header.
* *
* What we really need to do is output the raw headers ourselves so we can keep them separate. * What we really need to do is output the raw headers ourselves so we can keep them separate.
* *
*/ */
// header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";'); // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login')) if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
@ -136,7 +136,6 @@ if(! x($_SESSION,'sysmsg_info'))
* any plugins have been added or removed and reacts accordingly. * any plugins have been added or removed and reacts accordingly.
*/ */
if($install) if($install)
$a->module = 'install'; $a->module = 'install';
elseif($maintenance) elseif($maintenance)
@ -191,7 +190,7 @@ if(strlen($a->module)) {
// Compatibility with the Android Diaspora client // Compatibility with the Android Diaspora client
if ($a->module == "stream") if ($a->module == "stream")
$a->module = "network"; $a->module = "network";
$privateapps = get_config('config','private_addons'); $privateapps = get_config('config','private_addons');
if(is_array($a->plugins) && in_array($a->module,$a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) { if(is_array($a->plugins) && in_array($a->module,$a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) {
@ -320,10 +319,8 @@ if($a->module_loaded) {
$func = str_replace('-','_',current_theme()) . '_content_loaded'; $func = str_replace('-','_',current_theme()) . '_content_loaded';
$func($a); $func($a);
} }
} }
/* /*
* Create the page head after setting the language * Create the page head after setting the language
* and getting any auth credentials * and getting any auth credentials

View File

@ -123,7 +123,7 @@ function display_content(&$a, $update = 0) {
if($update) { if($update) {
$r = q("SELECT id FROM item WHERE item.uid = %d $r = q("SELECT id FROM item WHERE item.uid = %d
AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' )) AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
$sql_extra AND unseen = 1", $sql_extra AND unseen = 1",
intval($a->profile['uid']), intval($a->profile['uid']),
dbesc($item_id), dbesc($item_id),
@ -142,7 +142,7 @@ function display_content(&$a, $update = 0) {
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
and `item`.`moderated` = 0 and `item`.`moderated` = 0
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ) AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
AND uid = %d ) AND uid = %d )
$sql_extra $sql_extra
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
@ -171,7 +171,7 @@ function display_content(&$a, $update = 0) {
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
and `item`.`moderated` = 0 and `item`.`moderated` = 0
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d ) AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
intval(local_user()), intval(local_user()),
dbesc($item_uri), dbesc($item_uri),

View File

@ -376,7 +376,6 @@ function network_content(&$a, $update = 0) {
} }
} }
$o = ''; $o = '';
// item filter tabs // item filter tabs
@ -498,10 +497,6 @@ function network_content(&$a, $update = 0) {
// --- end item filter tabs // --- end item filter tabs
$contact_id = $a->cid; $contact_id = $a->cid;
require_once('include/acl_selectors.php'); require_once('include/acl_selectors.php');
@ -572,7 +567,6 @@ function network_content(&$a, $update = 0) {
} }
// We don't have to deal with ACLs on this page. You're looking at everything // We don't have to deal with ACLs on this page. You're looking at everything
// that belongs to you, hence you can see all of it. We will filter by group if // that belongs to you, hence you can see all of it. We will filter by group if
// desired. // desired.
@ -849,7 +843,6 @@ function network_content(&$a, $update = 0) {
$update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )'; $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
} }
// We aren't going to try and figure out at the item, group, and page // We aren't going to try and figure out at the item, group, and page
// level which items you've seen and which you haven't. If you're looking // level which items you've seen and which you haven't. If you're looking
// at the top level network page just mark everything seen. // at the top level network page just mark everything seen.
@ -864,7 +857,7 @@ function network_content(&$a, $update = 0) {
// on they just get buried deeper. It has happened to me a couple of times also. // on they just get buried deeper. It has happened to me a couple of times also.
if((! $group) && (! $cid) && (! $star)) { if((! $group) && (! $cid) && (! $star)) {
$r = q("UPDATE `item` SET `unseen` = 0 $r = q("UPDATE `item` SET `unseen` = 0
WHERE `unseen` = 1 AND `uid` = %d", WHERE `unseen` = 1 AND `uid` = %d",
intval(local_user()) intval(local_user())
); );

View File

@ -277,7 +277,7 @@ function profile_content(&$a, $update = 0) {
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid` $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM `item` FORCE INDEX (created) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1

View File

@ -130,10 +130,14 @@ class Conversation extends BaseObject {
global $a; global $a;
$result = array(); $result = array();
$i = 0;
foreach($this->threads as $item) { foreach($this->threads as $item) {
if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
continue; continue;
$item_data = $item->get_template_data($alike, $dlike); $item_data = $item->get_template_data($alike, $dlike);
if(!$item_data) { if(!$item_data) {
logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
return false; return false;