Several performance improvements.
This commit is contained in:
parent
5eeccd519a
commit
53c06a3625
9 changed files with 171 additions and 67 deletions
|
@ -52,7 +52,7 @@ function delivery_run(&$argv, &$argc){
|
|||
);
|
||||
if(! count($r)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
|
@ -67,7 +67,7 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
// It's ours to deliver. Remove it from the queue.
|
||||
|
||||
q("delete from deliverq where cmd = '%s' and item = %d and contact = %d limit 1",
|
||||
q("delete from deliverq where cmd = '%s' and item = %d and contact = %d",
|
||||
dbesc($cmd),
|
||||
dbesc($item_id),
|
||||
dbesc($contact_id)
|
||||
|
@ -331,7 +331,7 @@ function delivery_run(&$argv, &$argc){
|
|||
if($x && count($x)) {
|
||||
$write_flag = ((($x[0]['rel']) && ($x[0]['rel'] != CONTACT_IS_SHARING)) ? true : false);
|
||||
if((($owner['page-flags'] == PAGE_COMMUNITY) || ($write_flag)) && (! $x[0]['writable'])) {
|
||||
q("update contact set writable = 1 where id = %d limit 1",
|
||||
q("update contact set writable = 1 where id = %d",
|
||||
intval($x[0]['id'])
|
||||
);
|
||||
$x[0]['writable'] = 1;
|
||||
|
@ -430,7 +430,7 @@ function delivery_run(&$argv, &$argc){
|
|||
if($cmd === 'wall-new')
|
||||
$it = $items[0];
|
||||
else {
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($argv[2]),
|
||||
intval($uid)
|
||||
);
|
||||
|
|
|
@ -983,7 +983,23 @@ function item_store($arr,$force_parent = false) {
|
|||
$arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : '');
|
||||
$arr['origin'] = ((x($arr,'origin')) ? intval($arr['origin']) : 0 );
|
||||
$arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid());
|
||||
$arr['network'] = ((x($arr,'network')) ? trim($arr['network']) : '');
|
||||
|
||||
if ($arr['network'] == "") {
|
||||
$r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($arr['contact-id']),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
|
||||
if(count($r))
|
||||
$arr['network'] = $r[0]["network"];
|
||||
|
||||
// Fallback to friendica (why is it empty in some cases?)
|
||||
if ($arr['network'] == "")
|
||||
$arr['network'] = NETWORK_DFRN;
|
||||
|
||||
logger("item_store: Set network to ".$arr["network"]." for ".$arr["uri"], LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
$arr['thr-parent'] = $arr['parent-uri'];
|
||||
if($arr['parent-uri'] === $arr['uri']) {
|
||||
|
@ -1285,7 +1301,7 @@ function tag_deliver($uid,$item_id) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send a notification
|
||||
|
||||
|
@ -1730,12 +1746,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
|
|||
else {
|
||||
$resource_id = photo_new_resource();
|
||||
}
|
||||
|
||||
|
||||
$img_str = fetch_url($photo_url,true);
|
||||
// guess mimetype from headers or filename
|
||||
$type = guess_image_type($photo_url,true);
|
||||
|
||||
|
||||
|
||||
|
||||
$img = new Photo($img_str, $type);
|
||||
if($img->is_valid()) {
|
||||
if($have_photo) {
|
||||
|
@ -4082,6 +4098,9 @@ function drop_item($id,$interactive = true) {
|
|||
|
||||
// clean up item_id and sign meta-data tables
|
||||
|
||||
/*
|
||||
// Old code - caused very long queries and warning entries in the mysql logfiles:
|
||||
|
||||
$r = q("DELETE FROM item_id where iid in (select id from item where parent = %d and uid = %d)",
|
||||
intval($item['id']),
|
||||
intval($item['uid'])
|
||||
|
@ -4091,6 +4110,31 @@ function drop_item($id,$interactive = true) {
|
|||
intval($item['id']),
|
||||
intval($item['uid'])
|
||||
);
|
||||
*/
|
||||
|
||||
// The new code splits the queries since the mysql optimizer really has bad problems with subqueries
|
||||
|
||||
// Creating list of parents
|
||||
$r = q("select id from item where parent = %d and uid = %d",
|
||||
intval($item['id']),
|
||||
intval($item['uid'])
|
||||
);
|
||||
|
||||
$parentid = "";
|
||||
|
||||
foreach ($r AS $row) {
|
||||
if ($parentid != "")
|
||||
$parentid .= ", ";
|
||||
|
||||
$parentid .= $row["id"];
|
||||
}
|
||||
|
||||
// Now delete them
|
||||
if ($parentid != "") {
|
||||
$r = q("DELETE FROM item_id where iid in (%s)", dbesc($parentid));
|
||||
|
||||
$r = q("DELETE FROM sign where iid in (%s)", dbesc($parentid));
|
||||
}
|
||||
|
||||
// If it's the parent of a comment thread, kill all the kids
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
$session_exists = 0;
|
||||
$session_expire = 180000;
|
||||
|
||||
if(! function_exists('ref_session_open')) {
|
||||
if(! function_exists('ref_session_open')) {
|
||||
function ref_session_open ($s,$n) {
|
||||
return true;
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_read')) {
|
||||
if(! function_exists('ref_session_read')) {
|
||||
function ref_session_read ($id) {
|
||||
global $session_exists;
|
||||
if(x($id))
|
||||
|
@ -23,20 +23,20 @@ function ref_session_read ($id) {
|
|||
return '';
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_write')) {
|
||||
if(! function_exists('ref_session_write')) {
|
||||
function ref_session_write ($id,$data) {
|
||||
global $session_exists, $session_expire;
|
||||
if(! $id || ! $data) {
|
||||
return false;
|
||||
if(! $id || ! $data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$expire = time() + $session_expire;
|
||||
$default_expire = time() + 300;
|
||||
|
||||
if($session_exists)
|
||||
$r = q("UPDATE `session`
|
||||
SET `data` = '%s', `expire` = '%s'
|
||||
WHERE `sid` = '%s' LIMIT 1",
|
||||
$r = q("UPDATE `session`
|
||||
SET `data` = '%s', `expire` = '%s'
|
||||
WHERE `sid` = '%s'",
|
||||
dbesc($data), dbesc($expire), dbesc($id));
|
||||
else
|
||||
$r = q("INSERT INTO `session`
|
||||
|
@ -46,18 +46,18 @@ function ref_session_write ($id,$data) {
|
|||
return true;
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_close')) {
|
||||
if(! function_exists('ref_session_close')) {
|
||||
function ref_session_close() {
|
||||
return true;
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_destroy')) {
|
||||
if(! function_exists('ref_session_destroy')) {
|
||||
function ref_session_destroy ($id) {
|
||||
q("DELETE FROM `session` WHERE `sid` = '%s'", dbesc($id));
|
||||
return true;
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_gc')) {
|
||||
if(! function_exists('ref_session_gc')) {
|
||||
function ref_session_gc($expire) {
|
||||
q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
|
||||
q("OPTIMIZE TABLE `sess_data`");
|
||||
|
|
|
@ -92,8 +92,8 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
}
|
||||
|
||||
if((! $name) || (! $profile_url) || (! $profile_photo))
|
||||
continue;
|
||||
|
||||
continue;
|
||||
|
||||
$x = q("select * from `gcontact` where `nurl` = '%s' limit 1",
|
||||
dbesc(normalise_link($profile_url))
|
||||
);
|
||||
|
@ -102,8 +102,8 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
$gcid = $x[0]['id'];
|
||||
|
||||
if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo) {
|
||||
q("update gcontact set `name` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s'
|
||||
where `nurl` = '%s' limit 1",
|
||||
q("update gcontact set `name` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s'
|
||||
where `nurl` = '%s'",
|
||||
dbesc($name),
|
||||
dbesc($profile_photo),
|
||||
dbesc($connect_url),
|
||||
|
@ -146,7 +146,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
);
|
||||
}
|
||||
else {
|
||||
q("update glink set updated = '%s' where `cid` = %d and `uid` = %d and `gcid` = %d and zcid = %d limit 1",
|
||||
q("update glink set updated = '%s' where `cid` = %d and `uid` = %d and `gcid` = %d and zcid = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($cid),
|
||||
intval($uid),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue