1
1
Fork 0

Increased performance when storing items

This commit is contained in:
Michael Vogel 2016-10-05 16:12:53 +00:00
parent 66bec9475d
commit 5fb2e47809
3 changed files with 74 additions and 13 deletions

View file

@ -370,6 +370,13 @@ function uri_to_guid($uri) {
function item_store($arr,$force_parent = false, $notify = false, $dontcache = false) {
$perfdb = $a->performance["database"];
$perfdbw = $a->performance["database_write"];
$perfnet = $a->performance["network"];
$perffile = $a->performance["file"];
logger("Performance: Start", LOGGER_DEBUG);
// If it is a posting where users should get notifications, then define it as wall posting
if ($notify) {
$arr['wall'] = 1;
@ -914,6 +921,14 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
add_shadow_entry($arr);
}
$perfdb = $a->performance["database"] - $perfdb;
$perfdbw = $a->performance["database_write"] - $perfdbw;
$perfnet = $a->performance["network"] - $perfnet;
$perffile = $a->performance["file"] - $perffile;
logger("Performance: DB-R: ".round($perfdb - $perfdbw, 2)." - DB-W: ".round($perfdbw, 2)." - Net: ".round($perfnet, 2)." - File: ".round($perffile, 2), LOGGER_DEBUG);
//logger("Performance: DB-R: ".round($perfdb - $perfdbw, 2)." - DB-W: ".round($perfdbw, 2)." - Net: ".round($perfnet, 2), LOGGER_DEBUG);
check_item_notification($current_post, $uid);
if ($notify)

View file

@ -135,7 +135,9 @@ function update_thread($itemid, $setmention = false) {
$sql .= "`".$field."` = '".dbesc($data)."'";
}
logger("Pre Update Thread", LOGGER_DEBUG);
$result = q("UPDATE `thread` SET ".$sql." WHERE `iid` = %d", intval($itemid));
logger("Post Update Thread", LOGGER_DEBUG);
logger("Update thread for item ".$itemid." - guid ".$item["guid"]." - ".print_r($result, true)." ".print_r($item, true), LOGGER_DEBUG);
@ -145,6 +147,7 @@ function update_thread($itemid, $setmention = false) {
if (!$items)
return;
logger("Pre Update Item", LOGGER_DEBUG);
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
dbesc($item["title"]),
dbesc($item["body"]),
@ -152,6 +155,7 @@ function update_thread($itemid, $setmention = false) {
dbesc($item["rendered-hash"]),
intval($items[0]["id"])
);
logger("Post Update Item", LOGGER_DEBUG);
logger("Updating public shadow for post ".$items[0]["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG);
}

View file

@ -29,6 +29,13 @@ require_once('include/Contact.php');
function item_post(&$a) {
$perfdb = $a->performance["database"];
$perfdbw = $a->performance["database_write"];
$perfnet = $a->performance["network"];
$perffile = $a->performance["file"];
logger("Performance: Start", LOGGER_DEBUG);
if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter')))
return;
@ -460,7 +467,7 @@ function item_post(&$a) {
if(! count($r))
continue;
logger("Pre Photo", LOGGER_DEBUG);
$r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ",
dbesc($str_contact_allow),
@ -471,6 +478,7 @@ function item_post(&$a) {
intval($profile_uid),
dbesc( t('Wall Photos'))
);
logger("Post Photo", LOGGER_DEBUG);
}
}
@ -492,6 +500,7 @@ function item_post(&$a) {
intval($attach)
);
if(count($r)) {
logger("Pre Attach", LOGGER_DEBUG);
$r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
WHERE `uid` = %d AND `id` = %d",
dbesc($str_contact_allow),
@ -501,6 +510,7 @@ function item_post(&$a) {
intval($profile_uid),
intval($attach)
);
logger("Post Attach", LOGGER_DEBUG);
}
}
}
@ -762,6 +772,7 @@ function item_post(&$a) {
put_item_in_cache($datarray);
if($orig_post) {
logger("Pre Update", LOGGER_DEBUG);
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($datarray['title']),
dbesc($datarray['body']),
@ -775,6 +786,7 @@ function item_post(&$a) {
intval($post_id),
intval($profile_uid)
);
logger("Post Update", LOGGER_DEBUG);
create_tags_from_item($post_id);
create_files_from_item($post_id);
@ -793,7 +805,17 @@ function item_post(&$a) {
else
$post_id = 0;
if ($parent) {
// Inherit ACLs from the parent item.
/// @todo Check if really needed
$datarray['allow_cid'] = $parent_item['allow_cid'];
$datarray['allow_gid'] = $parent_item['allow_gid'];
$datarray['deny_cid'] = $parent_item['deny_cid'];
$datarray['deny_gid'] = $parent_item['deny_gid'];
$datarray['private'] = $parent_item['private'];
}
logger("Pre Insert", LOGGER_DEBUG);
$r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`,
`owner-name`,`owner-link`,`owner-avatar`, `owner-id`,
`author-name`, `author-link`, `author-avatar`, `author-id`,
@ -860,6 +882,8 @@ function item_post(&$a) {
dbesc($datarray['rendered-hash'])
);
logger("Post Insert", LOGGER_DEBUG);
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($datarray['uri']));
if(!count($r)) {
@ -880,15 +904,18 @@ function item_post(&$a) {
if($parent) {
logger("Pre Update last-child", LOGGER_DEBUG);
// This item is the last leaf and gets the comment box, clear any ancestors
$r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
$r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d AND `last-child`",
dbesc(datetime_convert()),
intval($parent)
);
update_thread($parent, true);
logger("Post Update last-child", LOGGER_DEBUG);
//Test: update_thread($parent, true);
// Inherit ACLs from the parent item.
/*
logger("Pre Update ACL", LOGGER_DEBUG);
$r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d
WHERE `id` = %d",
dbesc($parent_item['allow_cid']),
@ -898,7 +925,8 @@ function item_post(&$a) {
intval($parent_item['private']),
intval($post_id)
);
logger("Post Update ACL", LOGGER_DEBUG);
*/
if($contact_record != $author) {
notification(array(
'type' => NOTIFY_COMMENT,
@ -951,6 +979,7 @@ function item_post(&$a) {
if(! $parent)
$parent = $post_id;
logger("Pre Update Parent", LOGGER_DEBUG);
$r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
WHERE `id` = %d",
intval($parent),
@ -959,27 +988,32 @@ function item_post(&$a) {
dbesc(datetime_convert()),
intval($post_id)
);
logger("Pre Update Parent", LOGGER_DEBUG);
// photo comments turn the corresponding item visible to the profile wall
// This way we don't see every picture in your new photo album posted to your wall at once.
// They will show up as people comment on them.
if(! $parent_item['visible']) {
$r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d",
intval($parent_item['id'])
);
update_thread($parent_item['id']);
}
//if(! $parent_item['visible']) {
// logger("Pre Update Visible", LOGGER_DEBUG);
// $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d",
// intval($parent_item['id'])
// );
// logger("Post Update Visible", LOGGER_DEBUG);
//update_thread($parent_item['id']);
//}
// update the commented timestamp on the parent
q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d",
logger("Pre Update Commented", LOGGER_DEBUG);
q("UPDATE `item` SET `visible` = 1, `commented` = '%s', `changed` = '%s' WHERE `id` = %d",
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($parent)
);
logger("Post Update Commented", LOGGER_DEBUG);
if ($post_id != $parent)
update_thread($parent);
update_thread($parent, true);
call_hooks('post_local_end', $datarray);
@ -1036,6 +1070,14 @@ function item_post(&$a) {
logger('post_complete');
$perfdb = $a->performance["database"] - $perfdb;
$perfdbw = $a->performance["database_write"] - $perfdbw;
$perfnet = $a->performance["network"] - $perfnet;
$perffile = $a->performance["file"] - $perffile;
logger("Performance: DB-R: ".round($perfdb - $perfdbw, 2)." - DB-W: ".round($perfdbw, 2)." - Net: ".round($perfnet, 2)." - File: ".round($perffile, 2), LOGGER_DEBUG);
//logger("Performance: DB-R: ".round($perfdb - $perfdbw, 2)." - DB-W: ".round($perfdbw, 2)." - Net: ".round($perfnet, 2), LOGGER_DEBUG);
item_post_return($a->get_baseurl(), $api_source, $return_path);
// NOTREACHED
}