]> git.mxchange.org Git - friendica.git/commitdiff
Small performance tweaks for "item_store" as well.
authorMichael Vogel <ike@pirati.ca>
Fri, 7 Oct 2016 06:05:43 +0000 (06:05 +0000)
committerMichael Vogel <ike@pirati.ca>
Fri, 7 Oct 2016 06:05:43 +0000 (06:05 +0000)
include/items.php
include/poller.php
mod/item.php

index 0871d0bf817bb5c48a7fff346c7f84901fc4901b..5f0187ad97df61be53ec7a73e07e38f3f3a111c7 100644 (file)
@@ -370,13 +370,6 @@ 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;
@@ -676,7 +669,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
 
                        // If its a post from myself then tag the thread as "mention"
                        logger("item_store: Checking if parent ".$parent_id." has to be tagged as mention for user ".$arr['uid'], LOGGER_DEBUG);
-                       $u = q("select * from user where uid = %d limit 1", intval($arr['uid']));
+                       $u = q("SELECT `nickname` FROM `user` WHERE `uid` = %d", intval($arr['uid']));
                        if(count($u)) {
                                $a = get_app();
                                $self = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']);
@@ -686,8 +679,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                                        logger("item_store: tagged thread ".$parent_id." as mention for user ".$self, LOGGER_DEBUG);
                                }
                        }
-               }
-               else {
+               } else {
 
                        // Allow one to see reply tweets from status.net even when
                        // we don't have or can't see the original post.
@@ -742,6 +734,19 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                $arr["global"] = (count($isglobal) > 0);
        }
 
+       // ACL settings
+       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
+               $private = 1;
+       else
+               $private = $arr['private'];
+
+       $arr["allow_cid"] = $allow_cid;
+       $arr["allow_gid"] = $allow_gid;
+       $arr["deny_cid"] = $deny_cid;
+       $arr["deny_gid"] = $deny_gid;
+       $arr["private"] = $private;
+       $arr["deleted"] = $parent_deleted;
+
        // Fill the cache field
        put_item_in_cache($arr);
 
@@ -814,41 +819,38 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                                dbesc($arr['received']),
                                intval($arr['contact-id'])
                        );
+
+               // Now do the same for the system wide contacts with uid=0
+               if (!$arr['private']) {
+                       q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
+                               dbesc($arr['received']),
+                               dbesc($arr['received']),
+                               intval($arr['owner-id'])
+                       );
+
+                       if ($arr['owner-id'] != $arr['author-id'])
+                               q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
+                                       dbesc($arr['received']),
+                                       dbesc($arr['received']),
+                                       intval($arr['author-id'])
+                               );
+               }
        } else {
                logger('item_store: could not locate created item');
                return 0;
        }
 
-       if((! $parent_id) || ($arr['parent-uri'] === $arr['uri']))
+       if(!$parent_id || ($arr['parent-uri'] === $arr['uri']))
                $parent_id = $current_post;
 
-       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
-               $private = 1;
-       else
-               $private = $arr['private'];
-
-       // Set parent id - and also make sure to inherit the parent's ACLs.
-
-       $r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
-               `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d, `deleted` = %d WHERE `id` = %d",
+       // Set parent id
+       $r = q("UPDATE `item` SET `parent` = %d WHERE `id` = %d",
                intval($parent_id),
-               dbesc($allow_cid),
-               dbesc($allow_gid),
-               dbesc($deny_cid),
-               dbesc($deny_gid),
-               intval($private),
-               intval($parent_deleted),
                intval($current_post)
        );
 
        $arr['id'] = $current_post;
        $arr['parent'] = $parent_id;
-       $arr['allow_cid'] = $allow_cid;
-       $arr['allow_gid'] = $allow_gid;
-       $arr['deny_cid'] = $deny_cid;
-       $arr['deny_gid'] = $deny_gid;
-       $arr['private'] = $private;
-       $arr['deleted'] = $parent_deleted;
 
        // update the commented timestamp on the parent
        // Only update "commented" if it is really a comment
@@ -921,14 +923,6 @@ 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)
index fe4d4245af8df0a3a3d6fc4c6f94accbe2c5e7b5..61ec89e59766c0244b1791e48c5a560dea3ecc6f 100644 (file)
@@ -128,8 +128,16 @@ function poller_run(&$argv, &$argc){
 
                if (function_exists($funcname)) {
                        logger("Process ".$mypid." - Prio ".$r[0]["priority"]." - ID ".$r[0]["id"].": ".$funcname." ".$r[0]["parameter"]);
+
+                       // For better logging create a new process id for every worker call
+                       // But preserve the old one for the worker
+                       $old_process_id = $a->process_id;
+                       $a->process_id = uniqid("wrk", true);
+
                        $funcname($argv, $argc);
 
+                       $a->process_id = $old_process_id;
+
                        if ($cooldown > 0) {
                                logger("Process ".$mypid." - Prio ".$r[0]["priority"]." - ID ".$r[0]["id"].": ".$funcname." - in cooldown for ".$cooldown." seconds");
                                sleep($cooldown);
index 093842db5c5bd54fab8db51765f24818bbf0f5fe..e9056d08ccd9b6b3b24a812f1f38b907e4c31c02 100644 (file)
@@ -988,14 +988,18 @@ function item_post(&$a) {
                add_thread($post_id);
        else {
                update_thread($parent, true);
+
+               // Insert an item entry for UID=0 for global entries
+               // We have to remove or change some data before that,
+               // so that the post appear like a regular received post.
                unset($datarray['self']);
                unset($datarray['wall']);
                unset($datarray['origin']);
 
-               if (in_array($datarray['type'], array("net-comment", "wall-comment", "remote-comment")))
+               if (in_array($datarray['type'], array("net-comment", "wall-comment")))
                        $datarray['type'] = 'remote-comment';
-               else
-                       unset($datarray['type']);
+               elseif ($datarray['type'] == 'wall')
+                       $datarray['type'] = 'remote';
 
                add_shadow_entry($datarray);
        }