From 37ce5ce88624163c8a748bfe16a2def5c18a53dc Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 20 Dec 2016 07:14:59 +0000 Subject: [PATCH 01/48] Remove indexes that we don't use anymore --- include/dbstructure.php | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 94e8da4a4..5450c31f6 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -905,24 +905,24 @@ function db_definition($charset) { "uid_created" => array("uid","created"), "uid_unseen_contactid" => array("uid","unseen","contact-id"), "uid_network_received" => array("uid","network","received"), - "uid_received" => array("uid","received"), + // "uid_received" => array("uid","received"), "uid_network_commented" => array("uid","network","commented"), - "uid_commented" => array("uid","commented"), - "uid_title" => array("uid","title"), + // "uid_commented" => array("uid","commented"), + // "uid_title" => array("uid","title"), "uid_thrparent" => array("uid","thr-parent"), "uid_parenturi" => array("uid","parent-uri"), "uid_contactid_id" => array("uid","contact-id","id"), "uid_contactid_created" => array("uid","contact-id","created"), - "gcontactid_uid_created" => array("gcontact-id","uid","created"), + // "gcontactid_uid_created" => array("gcontact-id","uid","created"), "authorid_created" => array("author-id","created"), - "ownerid_created" => array("owner-id","created"), - "wall_body" => array("wall","body(6)"), - "uid_visible_moderated_created" => array("uid","visible","moderated","created"), + // "ownerid_created" => array("owner-id","created"), + // "wall_body" => array("wall","body(6)"), + // "uid_visible_moderated_created" => array("uid","visible","moderated","created"), "uid_uri" => array("uid", "uri"), "uid_wall_created" => array("uid","wall","created"), - "resource-id" => array("resource-id"), + // "resource-id" => array("resource-id"), "uid_type" => array("uid","type"), - "uid_starred_id" => array("uid","starred", "id"), + // "uid_starred_id" => array("uid","starred", "id"), "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), "uid_wall_parent_created" => array("uid","wall","parent","created"), "uid_type_changed" => array("uid","type","changed"), @@ -931,7 +931,7 @@ function db_definition($charset) { "uid_wall_changed" => array("uid","wall","changed"), "uid_eventid" => array("uid","event-id"), "uid_authorlink" => array("uid","author-link"), - "uid_ownerlink" => array("uid","owner-link"), + // "uid_ownerlink" => array("uid","owner-link"), ) ); $database["item_id"] = array( @@ -984,9 +984,9 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid" => array("uid"), - "guid" => array("guid"), - "convid" => array("convid"), - "reply" => array("reply"), + // "guid" => array("guid"), + // "convid" => array("convid"), + // "reply" => array("reply"), "uri" => array("uri"), "parent-uri" => array("parent-uri"), ) @@ -1058,7 +1058,7 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "master-parent-item" => array("master-parent-item"), - "receiver-uid" => array("receiver-uid"), + // "receiver-uid" => array("receiver-uid"), ) ); $database["oembed"] = array( @@ -1129,7 +1129,7 @@ function db_definition($charset) { "uid_profile" => array("uid", "profile"), "uid_album_created" => array("uid", "album", "created"), "resource-id" => array("resource-id"), - "guid" => array("guid"), + // "guid" => array("guid"), ) ); $database["poll"] = array( @@ -1268,7 +1268,7 @@ function db_definition($charset) { "cid" => array("cid"), "created" => array("created"), "last" => array("last"), - "network" => array("network"), + // "network" => array("network"), "batch" => array("batch"), ) ); @@ -1362,7 +1362,7 @@ function db_definition($charset) { "uid_term_tid" => array("uid","term","tid"), "type_term" => array("type","term"), "uid_otype_type_term_global_created" => array("uid","otype","type","term","global","created"), - "otype_type_term_tid" => array("otype","type","term","tid"), + // "otype_type_term_tid" => array("otype","type","term","tid"), "uid_otype_type_url" => array("uid","otype","type","url"), "guid" => array("guid"), ) @@ -1404,11 +1404,11 @@ function db_definition($charset) { "uid_network_created" => array("uid","network","created"), "uid_contactid_commented" => array("uid","contact-id","commented"), "uid_contactid_created" => array("uid","contact-id","created"), - "uid_gcontactid_commented" => array("uid","gcontact-id","commented"), - "uid_gcontactid_created" => array("uid","gcontact-id","created"), - "wall_private_received" => array("wall","private","received"), + // "uid_gcontactid_commented" => array("uid","gcontact-id","commented"), + // "uid_gcontactid_created" => array("uid","gcontact-id","created"), + // "wall_private_received" => array("wall","private","received"), "uid_created" => array("uid","created"), - "uid_commented" => array("uid","commented"), + // "uid_commented" => array("uid","commented"), ) ); $database["tokens"] = array( From 44d966574dc2edc58e1f5c0402a1956d4d554235 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 4 Jan 2017 19:13:50 +0000 Subject: [PATCH 02/48] Some more indexes and other query improvements --- include/dbclean.php | 7 ++++- include/dbstructure.php | 64 ++++++++++++++++++++--------------------- include/diaspora.php | 26 +++++++++++++++-- 3 files changed, 61 insertions(+), 36 deletions(-) diff --git a/include/dbclean.php b/include/dbclean.php index 0baece816..1f0e5834f 100644 --- a/include/dbclean.php +++ b/include/dbclean.php @@ -8,8 +8,9 @@ require_once("boot.php"); function dbclean_run(&$argv, &$argc) { global $a, $db; - if (is_null($a)) + if (is_null($a)) { $a = new App; + } if (is_null($db)) { @include(".htconfig.php"); @@ -21,6 +22,10 @@ function dbclean_run(&$argv, &$argc) { load_config('config'); load_config('system'); + if (!get_config("system", "dbclean")) { + return; + } + if ($argc == 2) { $stage = intval($argv[1]); } else { diff --git a/include/dbstructure.php b/include/dbstructure.php index 2dd7a6f18..706b3650d 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -538,7 +538,7 @@ function db_definition($charset) { "site-pubkey" => array("type" => "text"), "issued-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), + "url" => array("type" => "varchar(255)", "not null" => "1", "default" => "", "collation" => "bin"), "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), @@ -587,8 +587,8 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid" => array("uid"), - "addr_uid" => array("addr", "uid"), - "nurl" => array("nurl"), + "addr_uid" => array("addr(32)", "uid"), + "nurl" => array("nurl(32)"), ) ); $database["conv"] = array( @@ -669,7 +669,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "addr" => array("addr"), + "addr" => array("addr(32)"), ) ); $database["ffinder"] = array( @@ -692,7 +692,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "server" => array("server"), + "server" => array("server(32)"), ) ); $database["fsuggest"] = array( @@ -754,10 +754,10 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "nurl" => array("nurl"), - "name" => array("name"), - "nick" => array("nick"), - "addr" => array("addr"), + "nurl" => array("nurl(32)"), + "name" => array("name(32)"), + "nick" => array("nick(32)"), + "addr" => array("addr(32)"), "updated" => array("updated"), ) ); @@ -822,7 +822,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "nurl" => array("nurl"), + "nurl" => array("nurl(32)"), ) ); $database["hook"] = array( @@ -935,10 +935,10 @@ function db_definition($charset) { "uid_created" => array("uid","created"), "uid_unseen_contactid" => array("uid","unseen","contact-id"), "uid_network_received" => array("uid","network","received"), - // "uid_received" => array("uid","received"), + "uid_received" => array("uid","received"), "uid_network_commented" => array("uid","network","commented"), // "uid_commented" => array("uid","commented"), - // "uid_title" => array("uid","title"), + "uid_title" => array("uid","title"), "uid_thrparent" => array("uid","thr-parent"), "uid_parenturi" => array("uid","parent-uri"), "uid_contactid_id" => array("uid","contact-id","id"), @@ -950,18 +950,18 @@ function db_definition($charset) { // "uid_visible_moderated_created" => array("uid","visible","moderated","created"), "uid_uri" => array("uid", "uri"), "uid_wall_created" => array("uid","wall","created"), - // "resource-id" => array("resource-id"), + "resource-id" => array("resource-id"), "uid_type" => array("uid","type"), // "uid_starred_id" => array("uid","starred", "id"), "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), - "uid_wall_parent_created" => array("uid","wall","parent","created"), + // "uid_wall_parent_created" => array("uid","wall","parent","created"), "uid_type_changed" => array("uid","type","changed"), "contactid_verb" => array("contact-id","verb"), "deleted_changed" => array("deleted","changed"), "uid_wall_changed" => array("uid","wall","changed"), "uid_eventid" => array("uid","event-id"), "uid_authorlink" => array("uid","author-link"), - // "uid_ownerlink" => array("uid","owner-link"), + "uid_ownerlink" => array("uid","owner-link"), ) ); $database["item_id"] = array( @@ -976,7 +976,7 @@ function db_definition($charset) { "PRIMARY" => array("id"), "uid" => array("uid"), "sid" => array("sid"), - "service" => array("service"), + "service" => array("service(32)"), "iid" => array("iid"), ) ); @@ -1015,10 +1015,10 @@ function db_definition($charset) { "PRIMARY" => array("id"), "uid" => array("uid"), // "guid" => array("guid"), - // "convid" => array("convid"), + "convid" => array("convid"), // "reply" => array("reply"), "uri" => array("uri"), - "parent-uri" => array("parent-uri"), + "parent-uri" => array("parent-uri(64)"), ) ); $database["mailacct"] = array( @@ -1157,8 +1157,8 @@ function db_definition($charset) { "PRIMARY" => array("id"), "uid_contactid" => array("uid", "contact-id"), "uid_profile" => array("uid", "profile"), - "uid_album_created" => array("uid", "album", "created"), - "resource-id" => array("resource-id"), + "uid_album_created" => array("uid", "album(32)", "created"), + "resource-id" => array("resource-id(64)"), // "guid" => array("guid"), ) ); @@ -1252,7 +1252,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "hometown" => array("hometown"), + // "hometown" => array("hometown(32)"), ) ); $database["profile_check"] = array( @@ -1298,7 +1298,7 @@ function db_definition($charset) { "cid" => array("cid"), "created" => array("created"), "last" => array("last"), - // "network" => array("network"), + "network" => array("network"), "batch" => array("batch"), ) ); @@ -1325,7 +1325,7 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid" => array("uid"), - "term" => array("term"), + // "term" => array("term(32)"), ) ); $database["session"] = array( @@ -1337,7 +1337,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "sid" => array("sid"), + "sid" => array("sid(64)"), "expire" => array("expire"), ) ); @@ -1389,12 +1389,12 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("tid"), "oid_otype_type_term" => array("oid","otype","type","term"), - "uid_term_tid" => array("uid","term","tid"), - "type_term" => array("type","term"), - "uid_otype_type_term_global_created" => array("uid","otype","type","term","global","created"), + "uid_term_tid" => array("uid","term(32)","tid"), + "type_term" => array("type","term(32)"), + "uid_otype_type_term_global_created" => array("uid","otype","type","term(32)","global","created"), // "otype_type_term_tid" => array("otype","type","term","tid"), - "uid_otype_type_url" => array("uid","otype","type","url"), - "guid" => array("guid"), + "uid_otype_type_url" => array("uid","otype","type","url(64)"), + "guid" => array("guid(64)"), ) ); $database["thread"] = array( @@ -1438,7 +1438,7 @@ function db_definition($charset) { // "uid_gcontactid_created" => array("uid","gcontact-id","created"), // "wall_private_received" => array("wall","private","received"), "uid_created" => array("uid","created"), - // "uid_commented" => array("uid","commented"), + "uid_commented" => array("uid","commented"), ) ); $database["tokens"] = array( @@ -1502,7 +1502,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("uid"), - "nickname" => array("nickname"), + "nickname" => array("nickname(32)"), ) ); $database["userd"] = array( @@ -1512,7 +1512,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "username" => array("username"), + "username" => array("username(32)"), ) ); $database["workerqueue"] = array( diff --git a/include/diaspora.php b/include/diaspora.php index fbfc497b5..1cb4f0e92 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -736,13 +736,30 @@ class Diaspora { * @return The contact id */ private static function contact_by_handle($uid, $handle) { + + // First do a direct search on the contact table $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `addr` = '%s' LIMIT 1", intval($uid), dbesc($handle) ); - if ($r) + if ($r) { + //logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - first try", LOGGER_DEBUG); return $r[0]; + } else { + // We haven't found it? + // We use another function for it that will possibly create a contact entry + $cid = get_contact($handle, $uid); + + if ($cid > 0) { + $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid)); + + if (dbm::is_result($r)) { + logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - second try", LOGGER_DEBUG); + return $r[0]; + } + } + } $handle_parts = explode("@", $handle); $nurl_sql = "%%://".$handle_parts[1]."%%/profile/".$handle_parts[0]; @@ -751,9 +768,12 @@ class Diaspora { intval($uid), dbesc($nurl_sql) ); - if($r) + if(dbm::is_result($r)) { + logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - third try", LOGGER_DEBUG); return $r[0]; + } + logger("Haven't found contact for user ".$uid." and handle ".$handle, LOGGER_DEBUG); return false; } @@ -828,7 +848,7 @@ class Diaspora { * @return int|bool message id if the message already was stored into the system - or false. */ private static function message_exists($uid, $guid) { - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + $r = q("SELECT `guid` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($uid), dbesc($guid) ); From c2213760412f6d178d77451d69ae467534042457 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 4 Jan 2017 23:12:28 +0000 Subject: [PATCH 03/48] Some notification thingy --- include/dbstructure.php | 7 +++++-- include/enotify.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 706b3650d..646fc408c 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -538,7 +538,7 @@ function db_definition($charset) { "site-pubkey" => array("type" => "text"), "issued-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "url" => array("type" => "varchar(255)", "not null" => "1", "default" => "", "collation" => "bin"), + "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), @@ -1074,7 +1074,10 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "uid" => array("uid"), + "uid_hash" => array("uid", "hash"), + "uid_seen" => array("uid", "seen"), + "uid_type_link" => array("uid", "type", "link"), + "uid_link" => array("uid", "link"), ) ); $database["notify-threads"] = array( diff --git a/include/enotify.php b/include/enotify.php index aa29e117a..ebc27309d 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -105,7 +105,7 @@ function notification($params) { // If so don't create a second notification $p = null; - $p = q("SELECT `id` FROM `notify` WHERE (`type` = %d OR `type` = %d OR `type` = %d) AND `link` = '%s' AND `uid` = %d LIMIT 1", + $p = q("SELECT `id` FROM `notify` WHERE `type` IN (%d, %d, %d) AND `link` = '%s' AND `uid` = %d LIMIT 1", intval(NOTIFY_TAGSELF), intval(NOTIFY_COMMENT), intval(NOTIFY_SHARE), @@ -472,7 +472,7 @@ function notification($params) { // After we've stored everything, look again to see if there are any duplicates and if so remove them $p = null; - $p = q("SELECT `id` FROM `notify` WHERE (`type` = %d OR `type` = %d) AND `link` = '%s' AND `uid` = %d ORDER BY `id`", + $p = q("SELECT `id` FROM `notify` WHERE `type` IN (%d, %d) AND `link` = '%s' AND `uid` = %d ORDER BY `id`", intval(NOTIFY_TAGSELF), intval(NOTIFY_COMMENT), dbesc($params['link']), From cefb36fb67d88dcce9374aa7332770cccd861bf3 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 4 Jan 2017 23:28:51 +0000 Subject: [PATCH 04/48] Some more indexes on the contact table --- include/dbstructure.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 646fc408c..bb7757914 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -588,7 +588,8 @@ function db_definition($charset) { "PRIMARY" => array("id"), "uid" => array("uid"), "addr_uid" => array("addr(32)", "uid"), - "nurl" => array("nurl(32)"), + "nurl_uid" => array("nurl(32)", "uid"), + "nick_uid" => array("nick(32)", "uid"), ) ); $database["conv"] = array( From 00d7835ba6c8538fa5f9e65408b19535fbfb0b38 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 07:12:13 +0000 Subject: [PATCH 05/48] Some more contact indexes --- include/dbstructure.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/dbstructure.php b/include/dbstructure.php index bb7757914..46681c0d3 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -587,6 +587,8 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid" => array("uid"), + "uid_batch" => array("uid", "batch(64)"), + "uid_network" => array("uid", "network"), "addr_uid" => array("addr(32)", "uid"), "nurl_uid" => array("nurl(32)", "uid"), "nick_uid" => array("nick(32)", "uid"), From db1c6c06d619a7bd557d00e3b865063379316d9a Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 07:30:10 +0000 Subject: [PATCH 06/48] Finding the best index ... --- include/dbstructure.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 46681c0d3..2aea6ec58 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1078,9 +1078,10 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid_hash" => array("uid", "hash"), - "uid_seen" => array("uid", "seen"), + "uid_seen_date" => array("uid", "seen", "date"), "uid_type_link" => array("uid", "type", "link"), "uid_link" => array("uid", "link"), + "uid_date" => array("uid", "date"), ) ); $database["notify-threads"] = array( From a92c5f464d3f0ee25a539607ca5a4f1dd7f3297f Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 08:02:21 +0000 Subject: [PATCH 07/48] Hopefully this it it ... --- include/dbstructure.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dbstructure.php b/include/dbstructure.php index 2aea6ec58..eaa0202c5 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -587,6 +587,7 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid" => array("uid"), + "uid_self" => array("uid", "self"), "uid_batch" => array("uid", "batch(64)"), "uid_network" => array("uid", "network"), "addr_uid" => array("addr(32)", "uid"), From a4e437b56fbbcb43ce7bdea291dae04f52bab184 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 09:10:02 +0000 Subject: [PATCH 08/48] Contact testing --- include/dbstructure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index eaa0202c5..f0dad2679 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -588,7 +588,7 @@ function db_definition($charset) { "PRIMARY" => array("id"), "uid" => array("uid"), "uid_self" => array("uid", "self"), - "uid_batch" => array("uid", "batch(64)"), + "uid_network_batch_archive" => array("uid", "network", "batch(64)", "archive"), "uid_network" => array("uid", "network"), "addr_uid" => array("addr(32)", "uid"), "nurl_uid" => array("nurl(32)", "uid"), From 9c7a2d2f9ac360ee07a855bab244b17807ae458b Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 09:32:16 +0000 Subject: [PATCH 09/48] Another index --- include/dbstructure.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dbstructure.php b/include/dbstructure.php index f0dad2679..238fd1f36 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -592,6 +592,7 @@ function db_definition($charset) { "uid_network" => array("uid", "network"), "addr_uid" => array("addr(32)", "uid"), "nurl_uid" => array("nurl(32)", "uid"), + "url_uid" => array("url(32)", "uid"), "nick_uid" => array("nick(32)", "uid"), ) ); From 7aaf91a620cff8303d3052f1beb973d43d670431 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 13:16:27 +0000 Subject: [PATCH 10/48] Removing and adding some indexes --- include/dbstructure.php | 4 +--- include/redir.php | 14 +++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 238fd1f36..f7f44fd60 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -589,10 +589,8 @@ function db_definition($charset) { "uid" => array("uid"), "uid_self" => array("uid", "self"), "uid_network_batch_archive" => array("uid", "network", "batch(64)", "archive"), - "uid_network" => array("uid", "network"), "addr_uid" => array("addr(32)", "uid"), "nurl_uid" => array("nurl(32)", "uid"), - "url_uid" => array("url(32)", "uid"), "nick_uid" => array("nick(32)", "uid"), ) ); @@ -1022,7 +1020,7 @@ function db_definition($charset) { // "guid" => array("guid"), "convid" => array("convid"), // "reply" => array("reply"), - "uri" => array("uri"), + "uri" => array("uri(64)"), "parent-uri" => array("parent-uri(64)"), ) ); diff --git a/include/redir.php b/include/redir.php index d8bb76439..bbe8a11ec 100644 --- a/include/redir.php +++ b/include/redir.php @@ -27,13 +27,13 @@ function auto_redir(&$a, $contact_nick) { $baseurl = substr($baseurl, $domain_st + 3); $nurl = normalise_link($baseurl); - - $r = q("SELECT id FROM contact WHERE uid = ( SELECT uid FROM user WHERE nickname = '%s' LIMIT 1 ) - AND nick = '%s' AND self = 0 AND ( url LIKE '%%%s%%' or nurl LIKE '%%%s%%' ) AND blocked = 0 AND pending = 0 LIMIT 1", - dbesc($contact_nick), - dbesc($a->user['nickname']), - dbesc($baseurl), - dbesc($nurl) + /// @todo Why is there a query for "nurl" *and* "nurl"? Especially this normalising is strange. + $r = q("SELECT `id` FROM `contact` WHERE `uid` = (SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1) + AND `nick` = '%s' AND NOT `self` AND (`url` LIKE '%%%s%%' OR `nurl` LIKE '%%%s%%') AND NOT `blocked` AND NOT `pending` LIMIT 1", + dbesc($contact_nick), + dbesc($a->user['nickname']), + dbesc($baseurl), + dbesc($nurl) ); if ((! dbm::is_result($r)) || $r[0]['id'] == remote_user()) { From 6cdccbe2f67244213cf8c50e64ab1c6eed1d0e59 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 17:48:51 +0000 Subject: [PATCH 11/48] Will we now find the best index fort the contact? --- include/dbstructure.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/dbstructure.php b/include/dbstructure.php index f7f44fd60..7b3be5a31 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -588,6 +588,8 @@ function db_definition($charset) { "PRIMARY" => array("id"), "uid" => array("uid"), "uid_self" => array("uid", "self"), + "uid_batch" => array("uid", "batch"), + "uid_pending" => array("uid", "pending"), "uid_network_batch_archive" => array("uid", "network", "batch(64)", "archive"), "addr_uid" => array("addr(32)", "uid"), "nurl_uid" => array("nurl(32)", "uid"), From 2deb2b637b27e145f0ad49ac2bf07f12de53040d Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 22:23:00 +0000 Subject: [PATCH 12/48] Some new indexes and some removed. --- include/dbstructure.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 7b3be5a31..7b9b092c4 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -586,11 +586,13 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "uid" => array("uid"), + "uid_name" => array("uid", "name"), "uid_self" => array("uid", "self"), - "uid_batch" => array("uid", "batch"), + "alias_uid" => array("alias(32)", "uid"), "uid_pending" => array("uid", "pending"), - "uid_network_batch_archive" => array("uid", "network", "batch(64)", "archive"), + "uid_blocked" => array("uid", "blocked"), + "uid_rel_network_poll" => array("uid", "rel", "network", "poll(64)", "archive"), + "uid_network_batch" => array("uid", "network", "batch(64)"), "addr_uid" => array("addr(32)", "uid"), "nurl_uid" => array("nurl(32)", "uid"), "nick_uid" => array("nick(32)", "uid"), @@ -649,7 +651,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "uid" => array("uid"), + "uid_start" => array("uid", "start"), ) ); $database["fcontact"] = array( @@ -777,7 +779,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "cid_uid_gcid_zcid" => array("cid","uid","gcid","zcid"), + "cid_uid_gcid_zcid" => array("UNIQUE", "cid","uid","gcid","zcid"), "gcid" => array("gcid"), "zcid" => array("zcid"), ) @@ -804,7 +806,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "uid_gid_contactid" => array("uid","gid","contact-id"), + "uid_gid_contactid" => array("UNIQUE", "uid","gid","contact-id"), ) ); $database["gserver"] = array( @@ -1019,6 +1021,7 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid" => array("uid"), + "uid_seen" => array("uid", "seen"), // "guid" => array("guid"), "convid" => array("convid"), // "reply" => array("reply"), From ff3728be47cd02226a069f410cb4b85d5b23f291 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 22:51:31 +0000 Subject: [PATCH 13/48] Cleaning up the stuff --- include/dbstructure.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 7b9b092c4..8f47dc16e 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -944,24 +944,17 @@ function db_definition($charset) { "uid_network_received" => array("uid","network","received"), "uid_received" => array("uid","received"), "uid_network_commented" => array("uid","network","commented"), - // "uid_commented" => array("uid","commented"), "uid_title" => array("uid","title"), "uid_thrparent" => array("uid","thr-parent"), "uid_parenturi" => array("uid","parent-uri"), "uid_contactid_id" => array("uid","contact-id","id"), "uid_contactid_created" => array("uid","contact-id","created"), - // "gcontactid_uid_created" => array("gcontact-id","uid","created"), "authorid_created" => array("author-id","created"), - // "ownerid_created" => array("owner-id","created"), - // "wall_body" => array("wall","body(6)"), - // "uid_visible_moderated_created" => array("uid","visible","moderated","created"), "uid_uri" => array("uid", "uri"), "uid_wall_created" => array("uid","wall","created"), "resource-id" => array("resource-id"), "uid_type" => array("uid","type"), - // "uid_starred_id" => array("uid","starred", "id"), "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), - // "uid_wall_parent_created" => array("uid","wall","parent","created"), "uid_type_changed" => array("uid","type","changed"), "contactid_verb" => array("contact-id","verb"), "deleted_changed" => array("deleted","changed"), @@ -1022,9 +1015,7 @@ function db_definition($charset) { "PRIMARY" => array("id"), "uid" => array("uid"), "uid_seen" => array("uid", "seen"), - // "guid" => array("guid"), "convid" => array("convid"), - // "reply" => array("reply"), "uri" => array("uri(64)"), "parent-uri" => array("parent-uri(64)"), ) @@ -1100,7 +1091,6 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "master-parent-item" => array("master-parent-item"), - // "receiver-uid" => array("receiver-uid"), ) ); $database["oembed"] = array( @@ -1171,7 +1161,6 @@ function db_definition($charset) { "uid_profile" => array("uid", "profile"), "uid_album_created" => array("uid", "album(32)", "created"), "resource-id" => array("resource-id(64)"), - // "guid" => array("guid"), ) ); $database["poll"] = array( @@ -1264,7 +1253,6 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - // "hometown" => array("hometown(32)"), ) ); $database["profile_check"] = array( @@ -1337,7 +1325,6 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid" => array("uid"), - // "term" => array("term(32)"), ) ); $database["session"] = array( @@ -1404,7 +1391,6 @@ function db_definition($charset) { "uid_term_tid" => array("uid","term(32)","tid"), "type_term" => array("type","term(32)"), "uid_otype_type_term_global_created" => array("uid","otype","type","term(32)","global","created"), - // "otype_type_term_tid" => array("otype","type","term","tid"), "uid_otype_type_url" => array("uid","otype","type","url(64)"), "guid" => array("guid(64)"), ) @@ -1446,9 +1432,6 @@ function db_definition($charset) { "uid_network_created" => array("uid","network","created"), "uid_contactid_commented" => array("uid","contact-id","commented"), "uid_contactid_created" => array("uid","contact-id","created"), - // "uid_gcontactid_commented" => array("uid","gcontact-id","commented"), - // "uid_gcontactid_created" => array("uid","gcontact-id","created"), - // "wall_private_received" => array("wall","private","received"), "uid_created" => array("uid","created"), "uid_commented" => array("uid","commented"), ) From 58c229031edeeb6c230ac73837e12a4d95ebbe79 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 22:56:49 +0000 Subject: [PATCH 14/48] Now for the database version --- boot.php | 2 +- update.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index aad881376..5bf535ed9 100644 --- a/boot.php +++ b/boot.php @@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5.1-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1211 ); +define ( 'DB_UPDATE_VERSION', 1212 ); /** * @brief Constant with a HTML line break. diff --git a/update.php b/update.php index 3bd9cbe61..058536d82 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Fri, 6 Jan 2017 06:37:27 +0000 Subject: [PATCH 15/48] Removed some removed indexes --- include/Contact.php | 2 +- mod/community.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index b1f63cbdf..ea8a5f108 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -636,7 +636,7 @@ function posts_from_gcontact($a, $gcontact_id) { $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 (`gcontactid_uid_created`) + FROM `item` WHERE `gcontact-id` = %d AND $sql AND NOT `deleted` AND NOT `moderated` AND `visible` ORDER BY `item`.`created` DESC LIMIT %d, %d", diff --git a/mod/community.php b/mod/community.php index d7fd2bb93..b1b5c2fd2 100644 --- a/mod/community.php +++ b/mod/community.php @@ -121,7 +121,7 @@ function community_getitems($start, $itemspage) { return(community_getpublicitems($start, $itemspage)); $r = qu("SELECT %s - FROM `thread` FORCE INDEX (`wall_private_received`) + FROM `thread` INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' From 680b16d036a1dcdd72a6b960ae2a0f285d9d0223 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 6 Jan 2017 07:03:35 +0000 Subject: [PATCH 16/48] Added documentation --- doc/htconfig.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/htconfig.md b/doc/htconfig.md index fb257c3da..90bf78b87 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -25,6 +25,7 @@ Example: To set the directory value please add this line to your .htconfig.php: * **allowed_link_protocols** (Array) - Allowed protocols in links URLs, add at your own risk. http is always allowed. * **birthday_input_format** - Default value is "ymd". * **block_local_dir** (Boolean) - Blocks the access to the directory of the local users. +* **dbclean** (Boolean) - Enable the automatic database cleanup process * **default_service_class** - * **delivery_batch_count** - Number of deliveries per process. Default value is 1. (Disabled when using the worker) * **diaspora_test** (Boolean) - For development only. Disables the message transfer. From cb5df4d715a9710c2957ad4928762e90d5548298 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 6 Jan 2017 13:30:12 +0000 Subject: [PATCH 17/48] Some corrections --- include/diaspora.php | 9 +++------ include/redir.php | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 1cb4f0e92..2b9e61331 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -743,8 +743,7 @@ class Diaspora { dbesc($handle) ); - if ($r) { - //logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - first try", LOGGER_DEBUG); + if (dbm::is_result($r)) { return $r[0]; } else { // We haven't found it? @@ -755,7 +754,6 @@ class Diaspora { $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid)); if (dbm::is_result($r)) { - logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - second try", LOGGER_DEBUG); return $r[0]; } } @@ -769,7 +767,6 @@ class Diaspora { dbesc($nurl_sql) ); if(dbm::is_result($r)) { - logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - third try", LOGGER_DEBUG); return $r[0]; } @@ -848,12 +845,12 @@ class Diaspora { * @return int|bool message id if the message already was stored into the system - or false. */ private static function message_exists($uid, $guid) { - $r = q("SELECT `guid` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($uid), dbesc($guid) ); - if ($r) { + if (dbm::is_result($r)) { logger("message ".$guid." already exists for user ".$uid); return $r[0]["id"]; } diff --git a/include/redir.php b/include/redir.php index bbe8a11ec..d29159ed0 100644 --- a/include/redir.php +++ b/include/redir.php @@ -27,7 +27,7 @@ function auto_redir(&$a, $contact_nick) { $baseurl = substr($baseurl, $domain_st + 3); $nurl = normalise_link($baseurl); - /// @todo Why is there a query for "nurl" *and* "nurl"? Especially this normalising is strange. + /// @todo Why is there a query for "url" *and* "nurl"? Especially this normalising is strange. $r = q("SELECT `id` FROM `contact` WHERE `uid` = (SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1) AND `nick` = '%s' AND NOT `self` AND (`url` LIKE '%%%s%%' OR `nurl` LIKE '%%%s%%') AND NOT `blocked` AND NOT `pending` LIMIT 1", dbesc($contact_nick), From 414c5ddae08ca3a49ce570b481f2656fd0a58ea0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2017 09:05:52 +0000 Subject: [PATCH 18/48] Use Config class/Option to deactivate the count on albums --- doc/htconfig.md | 3 ++- include/dbclean.php | 6 +++++- include/photos.php | 35 +++++++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/doc/htconfig.md b/doc/htconfig.md index 90bf78b87..05a2a7a96 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -46,7 +46,8 @@ Example: To set the directory value please add this line to your .htconfig.php: * **max_processes_frontend** - Maximum number of concurrent database processes for foreground tasks. Default value is 20. * **memcache** (Boolean) - Use memcache. To use memcache the PECL extension "memcache" has to be installed and activated. * **memcache_host** - Hostname of the memcache daemon. Default is '127.0.0.1'. -* **memcache_port** - Portnumberof the memcache daemon. Default is 11211. +* **memcache_port** - Portnumber of the memcache daemon. Default is 11211. +* **no_count** (Boolean) - Don't do count calculations (currently only when showing albums) * **no_oembed** (Boolean) - Don't use OEmbed to fetch more information about a link. * **no_oembed_rich_content** (Boolean) - Don't show the rich content (e.g. embedded PDF). * **no_smilies** (Boolean) - Don't show smilies. diff --git a/include/dbclean.php b/include/dbclean.php index 1f0e5834f..29c417308 100644 --- a/include/dbclean.php +++ b/include/dbclean.php @@ -3,6 +3,10 @@ * @file include/dbclean.php * @brief The script is called from time to time to clean the database entries and remove orphaned data. */ + +use \Friendica\Core\Config; +use \Friendica\Core\PConfig; + require_once("boot.php"); function dbclean_run(&$argv, &$argc) { @@ -22,7 +26,7 @@ function dbclean_run(&$argv, &$argc) { load_config('config'); load_config('system'); - if (!get_config("system", "dbclean")) { + if (!Config::get('system', 'dbclean', false)) { return; } diff --git a/include/photos.php b/include/photos.php index 2beb23ffa..7cdd14bf6 100644 --- a/include/photos.php +++ b/include/photos.php @@ -4,6 +4,9 @@ * @brief Functions related to photo handling. */ +use \Friendica\Core\Config; +use \Friendica\Core\PConfig; + function getGps($exifCoord, $hemi) { $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0; $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0; @@ -42,16 +45,28 @@ function photo_albums($uid, $update = false) { $key = "photo_albums:".$uid.":".local_user().":".remote_user(); $albums = Cache::get($key); if (is_null($albums) OR $update) { - /// @todo This query needs to be renewed. It is really slow - // At this time we just store the data in the cache - $albums = qu("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album` - FROM `photo` USE INDEX (`uid_album_created`) - WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra - GROUP BY `album` ORDER BY `created` DESC", - intval($uid), - dbesc('Contact Photos'), - dbesc(t('Contact Photos')) - ); + if (!Config::get('system', 'no_count', false)) { + /// @todo This query needs to be renewed. It is really slow + // At this time we just store the data in the cache + $albums = qu("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album` + FROM `photo` USE INDEX (`uid_album_created`) + WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra + GROUP BY `album` ORDER BY `created` DESC", + intval($uid), + dbesc('Contact Photos'), + dbesc(t('Contact Photos')) + ); + } else { + // This query doesn't do the count and is much faster + $albums = qu("SELECT DISTINCT(`album`), '' AS `total` + FROM `photo` USE INDEX (`uid_album_created`) + WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra + GROUP BY `album` ORDER BY `created` DESC", + intval($uid), + dbesc('Contact Photos'), + dbesc(t('Contact Photos')) + ); + } Cache::set($key, $albums, CACHE_DAY); } return $albums; From 1b48799f08078d8120f23409e6333e59459da518 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2017 11:28:18 +0000 Subject: [PATCH 19/48] Don't do queries if not needed --- mod/photos.php | 25 +++++++++++++------------ mod/wall_attach.php | 30 ++++++++++++++++-------------- mod/wall_upload.php | 20 +++++++++----------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index e02694442..4b6704a71 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -818,21 +818,22 @@ function photos_post(&$a) { $imagedata = @file_get_contents($src); - - $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", - intval($a->data['user']['uid']) - ); - $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit'); - if (($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) { - notice( upgrade_message() . EOL ); - @unlink($src); - $foo = 0; - call_hooks('photo_post_end',$foo); - killme(); - } + if ($limit) { + $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", + intval($a->data['user']['uid']) + ); + $size = $r[0]['total']; + if (($size + strlen($imagedata)) > $limit) { + notice( upgrade_message() . EOL ); + @unlink($src); + $foo = 0; + call_hooks('photo_post_end',$foo); + killme(); + } + } $ph = new Photo($imagedata, $type); diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 525d3509c..fc8238974 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -112,23 +112,25 @@ function wall_attach_post(&$a) { killme(); } - $r = q("select sum(octet_length(data)) as total from attach where uid = %d ", - intval($page_owner_uid) - ); - $limit = service_class_fetch($page_owner_uid,'attach_upload_limit'); - if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) { - $msg = upgrade_message(true); - if ($r_json) { - echo json_encode(array('error'=>$msg)); - } else { - echo $msg. EOL ; - } - @unlink($src); - killme(); - } + if ($limit) { + $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", + intval($page_owner_uid) + ); + $size = $r[0]['total']; + if (($size + strlen($imagedata)) > $limit) { + $msg = upgrade_message(true); + if ($r_json) { + echo json_encode(array('error'=>$msg)); + } else { + echo $msg. EOL ; + } + @unlink($src); + killme(); + } + } $filedata = @file_get_contents($src); $mimetype = z_mime_content_type($filename); diff --git a/mod/wall_upload.php b/mod/wall_upload.php index eb2a92323..c789262c6 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -166,21 +166,19 @@ function wall_upload_post(&$a, $desktopmode = true) { intval($page_owner_uid) ); $size = $r[0]['total']; - } else - $size = 0; - if(($limit !== false) && (($size + strlen($imagedata)) > $limit)) { - $msg = upgrade_message(true); - if ($r_json) { - echo json_encode(array('error'=>$msg)); - } else { - echo $msg. EOL; + if (($size + strlen($imagedata)) > $limit) { + $msg = upgrade_message(true); + if ($r_json) { + echo json_encode(array('error'=>$msg)); + } else { + echo $msg. EOL; + } + @unlink($src); + killme(); } - @unlink($src); - killme(); } - $imagedata = @file_get_contents($src); $ph = new Photo($imagedata, $filetype); From c2543f918b3c9fc6cc8655fb2f4e9f99752e0901 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2017 13:52:30 +0000 Subject: [PATCH 20/48] Last minutes changes --- include/dbstructure.php | 5 ++++- include/diaspora.php | 2 +- mod/photos.php | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 8f47dc16e..e519562b4 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -806,7 +806,9 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "uid_gid_contactid" => array("UNIQUE", "uid","gid","contact-id"), + "cid_contactid" => array("cid", "contact-id"), + "uid_contactid" => array("uid", "contact-id"), + "uid_gid_contactid" => array("UNIQUE", "uid", "gid", "contact-id"), ) ); $database["gserver"] = array( @@ -1160,6 +1162,7 @@ function db_definition($charset) { "uid_contactid" => array("uid", "contact-id"), "uid_profile" => array("uid", "profile"), "uid_album_created" => array("uid", "album(32)", "created"), + "uid_album_resource-id_created" => array("uid", "album(32)", "resource-id(64)", "created"), "resource-id" => array("resource-id(64)"), ) ); diff --git a/include/diaspora.php b/include/diaspora.php index 2b9e61331..54bc74454 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -766,7 +766,7 @@ class Diaspora { intval($uid), dbesc($nurl_sql) ); - if(dbm::is_result($r)) { + if (dbm::is_result($r)) { return $r[0]; } diff --git a/mod/photos.php b/mod/photos.php index 4b6704a71..4880e7feb 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -182,11 +182,11 @@ function photos_post(&$a) { return; // NOTREACHED } - $r = qu("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d", + $r = qu("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d", dbesc($album), intval($page_owner_uid) ); - if (! dbm::is_result($r)) { + if (!dbm::is_result($r)) { notice( t('Album not found.') . EOL); goaway($_SESSION['photo_return']); return; // NOTREACHED From f14cd2920a6d27141289cc2b81aaf0dfabe02079 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2017 22:04:57 +0000 Subject: [PATCH 21/48] database.sql was updated --- database.sql | 94 +++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/database.sql b/database.sql index 2e83c33a6..becd14fc7 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 3.5.1-dev (Asparagus) --- DB_UPDATE_VERSION 1211 +-- DB_UPDATE_VERSION 1212 -- ------------------------------------------ @@ -174,9 +174,16 @@ CREATE TABLE IF NOT EXISTS `contact` ( `fetch_further_information` tinyint(1) NOT NULL DEFAULT 0, `ffi_keyword_blacklist` mediumtext, PRIMARY KEY(`id`), - INDEX `uid` (`uid`), - INDEX `addr_uid` (`addr`,`uid`), - INDEX `nurl` (`nurl`) + INDEX `uid_name` (`uid`,`name`), + INDEX `uid_self` (`uid`,`self`), + INDEX `alias_uid` (`alias`(32),`uid`), + INDEX `uid_pending` (`uid`,`pending`), + INDEX `uid_blocked` (`uid`,`blocked`), + INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`), + INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)), + INDEX `addr_uid` (`addr`(32),`uid`), + INDEX `nurl_uid` (`nurl`(32),`uid`), + INDEX `nick_uid` (`nick`(32),`uid`) ) DEFAULT CHARSET=utf8mb4; -- @@ -232,7 +239,7 @@ CREATE TABLE IF NOT EXISTS `event` ( `deny_cid` mediumtext, `deny_gid` mediumtext, PRIMARY KEY(`id`), - INDEX `uid` (`uid`) + INDEX `uid_start` (`uid`,`start`) ) DEFAULT CHARSET=utf8mb4; -- @@ -257,7 +264,7 @@ CREATE TABLE IF NOT EXISTS `fcontact` ( `pubkey` text, `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(`id`), - INDEX `addr` (`addr`) + INDEX `addr` (`addr`(32)) ) DEFAULT CHARSET=utf8mb4; -- @@ -280,7 +287,7 @@ CREATE TABLE IF NOT EXISTS `fserver` ( `posturl` varchar(255) NOT NULL DEFAULT '', `key` text, PRIMARY KEY(`id`), - INDEX `server` (`server`) + INDEX `server` (`server`(32)) ) DEFAULT CHARSET=utf8mb4; -- @@ -342,10 +349,10 @@ CREATE TABLE IF NOT EXISTS `gcontact` ( `generation` tinyint(3) NOT NULL DEFAULT 0, `server_url` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY(`id`), - INDEX `nurl` (`nurl`), - INDEX `name` (`name`), - INDEX `nick` (`nick`), - INDEX `addr` (`addr`), + INDEX `nurl` (`nurl`(32)), + INDEX `name` (`name`(32)), + INDEX `nick` (`nick`(32)), + INDEX `addr` (`addr`(32)), INDEX `updated` (`updated`) ) DEFAULT CHARSET=utf8mb4; @@ -360,7 +367,7 @@ CREATE TABLE IF NOT EXISTS `glink` ( `zcid` int(11) NOT NULL DEFAULT 0, `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(`id`), - INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`), + UNIQUE INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`), INDEX `gcid` (`gcid`), INDEX `zcid` (`zcid`) ) DEFAULT CHARSET=utf8mb4; @@ -387,7 +394,9 @@ CREATE TABLE IF NOT EXISTS `group_member` ( `gid` int(10) unsigned NOT NULL DEFAULT 0, `contact-id` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY(`id`), - INDEX `uid_gid_contactid` (`uid`,`gid`,`contact-id`) + INDEX `cid_contactid` (`cid`,`contact-id`), + INDEX `uid_contactid` (`uid`,`contact-id`), + UNIQUE INDEX `uid_gid_contactid` (`uid`,`gid`,`contact-id`) ) DEFAULT CHARSET=utf8mb4; -- @@ -410,7 +419,7 @@ CREATE TABLE IF NOT EXISTS `gserver` ( `last_contact` datetime DEFAULT '0000-00-00 00:00:00', `last_failure` datetime DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(`id`), - INDEX `nurl` (`nurl`) + INDEX `nurl` (`nurl`(32)) ) DEFAULT CHARSET=utf8mb4; -- @@ -525,24 +534,17 @@ CREATE TABLE IF NOT EXISTS `item` ( INDEX `uid_network_received` (`uid`,`network`,`received`), INDEX `uid_received` (`uid`,`received`), INDEX `uid_network_commented` (`uid`,`network`,`commented`), - INDEX `uid_commented` (`uid`,`commented`), INDEX `uid_title` (`uid`,`title`), INDEX `uid_thrparent` (`uid`,`thr-parent`), INDEX `uid_parenturi` (`uid`,`parent-uri`), INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), - INDEX `gcontactid_uid_created` (`gcontact-id`,`uid`,`created`), INDEX `authorid_created` (`author-id`,`created`), - INDEX `ownerid_created` (`owner-id`,`created`), - INDEX `wall_body` (`wall`,`body`(6)), - INDEX `uid_visible_moderated_created` (`uid`,`visible`,`moderated`,`created`), INDEX `uid_uri` (`uid`,`uri`), INDEX `uid_wall_created` (`uid`,`wall`,`created`), INDEX `resource-id` (`resource-id`), INDEX `uid_type` (`uid`,`type`), - INDEX `uid_starred_id` (`uid`,`starred`,`id`), INDEX `contactid_allowcid_allowpid_denycid_denygid` (`contact-id`,`allow_cid`(10),`allow_gid`(10),`deny_cid`(10),`deny_gid`(10)), - INDEX `uid_wall_parent_created` (`uid`,`wall`,`parent`,`created`), INDEX `uid_type_changed` (`uid`,`type`,`changed`), INDEX `contactid_verb` (`contact-id`,`verb`), INDEX `deleted_changed` (`deleted`,`changed`), @@ -564,7 +566,7 @@ CREATE TABLE IF NOT EXISTS `item_id` ( PRIMARY KEY(`id`), INDEX `uid` (`uid`), INDEX `sid` (`sid`), - INDEX `service` (`service`), + INDEX `service` (`service`(32)), INDEX `iid` (`iid`) ) DEFAULT CHARSET=utf8mb4; @@ -602,11 +604,10 @@ CREATE TABLE IF NOT EXISTS `mail` ( `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(`id`), INDEX `uid` (`uid`), - INDEX `guid` (`guid`), + INDEX `uid_seen` (`uid`,`seen`), INDEX `convid` (`convid`), - INDEX `reply` (`reply`), - INDEX `uri` (`uri`), - INDEX `parent-uri` (`parent-uri`) + INDEX `uri` (`uri`(64)), + INDEX `parent-uri` (`parent-uri`(64)) ) DEFAULT CHARSET=utf8mb4; -- @@ -662,7 +663,11 @@ CREATE TABLE IF NOT EXISTS `notify` ( `name_cache` tinytext, `msg_cache` mediumtext, PRIMARY KEY(`id`), - INDEX `uid` (`uid`) + INDEX `uid_hash` (`uid`,`hash`), + INDEX `uid_seen_date` (`uid`,`seen`,`date`), + INDEX `uid_type_link` (`uid`,`type`,`link`), + INDEX `uid_link` (`uid`,`link`), + INDEX `uid_date` (`uid`,`date`) ) DEFAULT CHARSET=utf8mb4; -- @@ -675,8 +680,7 @@ CREATE TABLE IF NOT EXISTS `notify-threads` ( `parent-item` int(10) unsigned NOT NULL DEFAULT 0, `receiver-uid` int(11) NOT NULL DEFAULT 0, PRIMARY KEY(`id`), - INDEX `master-parent-item` (`master-parent-item`), - INDEX `receiver-uid` (`receiver-uid`) + INDEX `master-parent-item` (`master-parent-item`) ) DEFAULT CHARSET=utf8mb4; -- @@ -745,9 +749,9 @@ CREATE TABLE IF NOT EXISTS `photo` ( PRIMARY KEY(`id`), INDEX `uid_contactid` (`uid`,`contact-id`), INDEX `uid_profile` (`uid`,`profile`), - INDEX `uid_album_created` (`uid`,`album`,`created`), - INDEX `resource-id` (`resource-id`), - INDEX `guid` (`guid`) + INDEX `uid_album_created` (`uid`,`album`(32),`created`), + INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`(64),`created`), + INDEX `resource-id` (`resource-id`(64)) ) DEFAULT CHARSET=utf8mb4; -- @@ -839,8 +843,7 @@ CREATE TABLE IF NOT EXISTS `profile` ( `thumb` varchar(255) NOT NULL DEFAULT '', `publish` tinyint(1) NOT NULL DEFAULT 0, `net-publish` tinyint(1) NOT NULL DEFAULT 0, - PRIMARY KEY(`id`), - INDEX `hometown` (`hometown`) + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8mb4; -- @@ -912,8 +915,7 @@ CREATE TABLE IF NOT EXISTS `search` ( `uid` int(11) NOT NULL DEFAULT 0, `term` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY(`id`), - INDEX `uid` (`uid`), - INDEX `term` (`term`) + INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8mb4; -- @@ -925,7 +927,7 @@ CREATE TABLE IF NOT EXISTS `session` ( `data` text, `expire` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY(`id`), - INDEX `sid` (`sid`), + INDEX `sid` (`sid`(64)), INDEX `expire` (`expire`) ) DEFAULT CHARSET=utf8mb4; @@ -977,12 +979,11 @@ CREATE TABLE IF NOT EXISTS `term` ( `uid` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY(`tid`), INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`), - INDEX `uid_term_tid` (`uid`,`term`,`tid`), - INDEX `type_term` (`type`,`term`), - INDEX `uid_otype_type_term_global_created` (`uid`,`otype`,`type`,`term`,`global`,`created`), - INDEX `otype_type_term_tid` (`otype`,`type`,`term`,`tid`), - INDEX `uid_otype_type_url` (`uid`,`otype`,`type`,`url`), - INDEX `guid` (`guid`) + INDEX `uid_term_tid` (`uid`,`term`(32),`tid`), + INDEX `type_term` (`type`,`term`(32)), + INDEX `uid_otype_type_term_global_created` (`uid`,`otype`,`type`,`term`(32),`global`,`created`), + INDEX `uid_otype_type_url` (`uid`,`otype`,`type`,`url`(64)), + INDEX `guid` (`guid`(64)) ) DEFAULT CHARSET=utf8mb4; -- @@ -1022,9 +1023,6 @@ CREATE TABLE IF NOT EXISTS `thread` ( INDEX `uid_network_created` (`uid`,`network`,`created`), INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), - INDEX `uid_gcontactid_commented` (`uid`,`gcontact-id`,`commented`), - INDEX `uid_gcontactid_created` (`uid`,`gcontact-id`,`created`), - INDEX `wall_private_received` (`wall`,`private`,`received`), INDEX `uid_created` (`uid`,`created`), INDEX `uid_commented` (`uid`,`commented`) ) DEFAULT CHARSET=utf8mb4; @@ -1090,7 +1088,7 @@ CREATE TABLE IF NOT EXISTS `user` ( `deny_gid` mediumtext, `openidserver` text, PRIMARY KEY(`uid`), - INDEX `nickname` (`nickname`) + INDEX `nickname` (`nickname`(32)) ) DEFAULT CHARSET=utf8mb4; -- @@ -1100,7 +1098,7 @@ CREATE TABLE IF NOT EXISTS `userd` ( `id` int(11) NOT NULL auto_increment, `username` varchar(255) NOT NULL, PRIMARY KEY(`id`), - INDEX `username` (`username`) + INDEX `username` (`username`(32)) ) DEFAULT CHARSET=utf8mb4; -- From 28b2e599fb6ee3ee9ca0f3e3791482686cdbb902 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Jan 2017 20:11:15 +0000 Subject: [PATCH 22/48] it should be "gid" not "cid" --- include/dbstructure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index e519562b4..5c89f49fb 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -806,7 +806,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), - "cid_contactid" => array("cid", "contact-id"), + "gid_contactid" => array("gid", "contact-id"), "uid_contactid" => array("uid", "contact-id"), "uid_gid_contactid" => array("UNIQUE", "uid", "gid", "contact-id"), ) From 906c7d528b819882f144a139c23ca87c6ca241e5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Jan 2017 20:35:41 +0000 Subject: [PATCH 23/48] Bugfix: Answers to OStatus posts should never reach Diaspora --- include/notifier.php | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/include/notifier.php b/include/notifier.php index 84efe7952..6655e4a77 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -220,6 +220,9 @@ function notifier_run(&$argv, &$argc){ $hub = get_config('system','huburl'); + // Should the post be transmitted to Diaspora? + $diaspora_delivery = true; + // If this is a public conversation, notify the feed hub $public_message = true; @@ -240,7 +243,7 @@ function notifier_run(&$argv, &$argc){ $thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d", dbesc($target_item["thr-parent"]), intval($target_item["uid"])); - logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG); + logger('GUID: '.$target_item["guid"].': Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG); // This is IMPORTANT!!!! @@ -396,6 +399,8 @@ function notifier_run(&$argv, &$argc){ // We have not only to look at the parent, since it could be a Friendica thread. if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) { + $diaspora_delivery = false; + logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent[0]['author-link']." - Owner: ".$thr_parent[0]['owner-link'], LOGGER_DEBUG); // Send a salmon to the parent author @@ -413,7 +418,7 @@ function notifier_run(&$argv, &$argc){ } // Send a salmon to the parent owner - $r = q("SELECT `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''", + $r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''", dbesc(normalise_link($thr_parent[0]['owner-link'])), intval($uid)); if ($r) @@ -443,12 +448,6 @@ function notifier_run(&$argv, &$argc){ $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."')"; } else $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."', '".NETWORK_DIASPORA."', '".NETWORK_MAIL."', '".NETWORK_MAIL2."')"; - - $r = q("SELECT * FROM `contact` WHERE `id` IN ($conversant_str) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra); - - if (dbm::is_result($r)) - $contacts = $r; - } else $public_message = false; @@ -479,11 +478,10 @@ function notifier_run(&$argv, &$argc){ if ($relocate) $r = $recipients_relocate; else - $r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`", + $r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra, dbesc($recip_str) ); - $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval'))); // If we are using the worker we don't need a delivery interval @@ -570,17 +568,20 @@ function notifier_run(&$argv, &$argc){ if($public_message) { - if (!$followup) - $r0 = Diaspora::relay_list(); - else - $r0 = array(); + $r0 = array(); + $r1 = array(); - $r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s' - AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch` ORDER BY rand()", - dbesc(NETWORK_DIASPORA), - intval($owner['uid']), - intval(CONTACT_IS_SHARING) - ); + if ($diaspora_delivery) { + if (!$followup) + $r0 = Diaspora::relay_list(); + + $r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s' + AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch` ORDER BY rand()", + dbesc(NETWORK_DIASPORA), + intval($owner['uid']), + intval(CONTACT_IS_SHARING) + ); + } $r2 = q("SELECT `id`, `name`,`network` FROM `contact` WHERE `network` in ( '%s', '%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` From fc60e7f5ddb4f5f704f34ce9a11329039f2fb3e0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Jan 2017 22:29:55 +0000 Subject: [PATCH 24/48] Making Hypolite smile --- include/notifier.php | 189 +++++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 87 deletions(-) diff --git a/include/notifier.php b/include/notifier.php index 6655e4a77..a56f1f89f 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -43,11 +43,11 @@ require_once('include/salmon.php'); function notifier_run(&$argv, &$argc){ global $a, $db; - if(is_null($a)){ + if (is_null($a)) { $a = new App; } - if(is_null($db)) { + if (is_null($db)) { @include(".htconfig.php"); require_once("include/dba.php"); $db = new dba($db_host, $db_user, $db_pass, $db_data); @@ -64,8 +64,9 @@ function notifier_run(&$argv, &$argc){ load_hooks(); - if($argc < 3) + if ($argc < 3) { return; + } $a->set_baseurl(get_config('system','url')); @@ -77,7 +78,7 @@ function notifier_run(&$argv, &$argc){ case 'mail': default: $item_id = intval($argv[2]); - if(! $item_id){ + if (! $item_id) { return; } break; @@ -93,21 +94,20 @@ function notifier_run(&$argv, &$argc){ $normal_mode = true; - if($cmd === 'mail') { + if ($cmd === 'mail') { $normal_mode = false; $mail = true; $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1", intval($item_id) ); - if(! count($message)){ + if (! count($message)) { return; } $uid = $message[0]['uid']; $recipients[] = $message[0]['contact-id']; $item = $message[0]; - } - elseif($cmd === 'expire') { + } elseif ($cmd === 'expire') { $normal_mode = false; $expire = true; $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 @@ -116,22 +116,23 @@ function notifier_run(&$argv, &$argc){ ); $uid = $item_id; $item_id = 0; - if(! count($items)) + if (! count($items)) { return; - } - elseif($cmd === 'suggest') { + } + } elseif ($cmd === 'suggest') { $normal_mode = false; $fsuggest = true; $suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item_id) ); - if(! count($suggest)) + if (! count($suggest)) { return; + } $uid = $suggest[0]['uid']; $recipients[] = $suggest[0]['cid']; $item = $suggest[0]; - } elseif($cmd === 'removeme') { + } elseif ($cmd === 'removeme') { $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags`, `user`.`prvnets`, `user`.`account-type`, `user`.`guid` @@ -150,15 +151,15 @@ function notifier_run(&$argv, &$argc){ $self = $r[0]; $r = q("SELECT * FROM `contact` WHERE NOT `self` AND `uid` = %d", intval($item_id)); - if(!$r) + if (!$r) { return; - + } require_once('include/Contact.php'); - foreach($r as $contact) { + foreach ($r as $contact) { terminate_friendship($user, $self, $contact); } return; - } elseif($cmd === 'relocate') { + } elseif ($cmd === 'relocate') { $normal_mode = false; $relocate = true; $uid = $item_id; @@ -170,7 +171,7 @@ function notifier_run(&$argv, &$argc){ intval($item_id) ); - if((! dbm::is_result($r)) || (! intval($r[0]['parent']))) { + if ((! dbm::is_result($r)) || (! intval($r[0]['parent']))) { return; } @@ -184,18 +185,18 @@ function notifier_run(&$argv, &$argc){ intval($parent_id) ); - if(! count($items)) { + if (! count($items)) { return; } // avoid race condition with deleting entries - if($items[0]['deleted']) { - foreach($items as $item) + if ($items[0]['deleted']) { + foreach ($items as $item) $item['deleted'] = 1; } - if((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) { + if ((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) { logger('notifier: top level post'); $top_level = true; } @@ -232,7 +233,7 @@ function notifier_run(&$argv, &$argc){ // fill this in with a single salmon slap if applicable $slap = ''; - if(! ($mail || $fsuggest || $relocate)) { + if (! ($mail || $fsuggest || $relocate)) { $slap = ostatus::salmon($target_item,$owner); @@ -267,9 +268,9 @@ function notifier_run(&$argv, &$argc){ $localhost = str_replace('www.','',$a->get_hostname()); - if(strpos($localhost,':')) + if (strpos($localhost,':')) { $localhost = substr($localhost,0,strpos($localhost,':')); - + } /** * * Be VERY CAREFUL if you make any changes to the following several lines. Seemingly innocuous changes @@ -280,12 +281,12 @@ function notifier_run(&$argv, &$argc){ $relay_to_owner = false; - if(!$top_level && ($parent['wall'] == 0) && !$expire && (stristr($target_item['uri'],$localhost))) { + if (!$top_level && ($parent['wall'] == 0) && !$expire && (stristr($target_item['uri'],$localhost))) { $relay_to_owner = true; } - if(($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && !$top_level) { + if (($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && !$top_level) { $relay_to_owner = true; } @@ -293,13 +294,13 @@ function notifier_run(&$argv, &$argc){ // we will just use it as a fallback test // later we will be able to use it as the primary test of whether or not to relay. - if(! $target_item['origin']) + if (! $target_item['origin']) { $relay_to_owner = false; - - if($parent['origin']) + } + if ($parent['origin']) { $relay_to_owner = false; - - if($relay_to_owner) { + } + if ($relay_to_owner) { logger('notifier: followup '.$target_item["guid"], LOGGER_DEBUG); // local followup to remote post $followup = true; @@ -326,7 +327,7 @@ function notifier_run(&$argv, &$argc){ dbesc(NETWORK_DFRN) ); if (dbm::is_result($r)) - foreach($r as $rr) + foreach ($r as $rr) $recipients_followup[] = $rr['id']; } } @@ -338,12 +339,12 @@ function notifier_run(&$argv, &$argc){ // don't send deletions onward for other people's stuff - if($target_item['deleted'] && (! intval($target_item['wall']))) { + if ($target_item['deleted'] && (! intval($target_item['wall']))) { logger('notifier: ignoring delete notification for non-wall item'); return; } - if((strlen($parent['allow_cid'])) + if ((strlen($parent['allow_cid'])) || (strlen($parent['allow_gid'])) || (strlen($parent['deny_cid'])) || (strlen($parent['deny_gid']))) { @@ -358,24 +359,23 @@ function notifier_run(&$argv, &$argc){ // if our parent is a public forum (forum_mode == 1), uplink to the origional author causing // a delivery fork. private groups (forum_mode == 2) do not uplink - if((intval($parent['forum_mode']) == 1) && (! $top_level) && ($cmd !== 'uplink')) { + if ((intval($parent['forum_mode']) == 1) && (! $top_level) && ($cmd !== 'uplink')) { proc_run(PRIORITY_HIGH,'include/notifier.php','uplink',$item_id); } $conversants = array(); - foreach($items as $item) { + foreach ($items as $item) { $recipients[] = $item['contact-id']; $conversants[] = $item['contact-id']; // pull out additional tagged people to notify (if public message) - if($public_message && strlen($item['inform'])) { + if ($public_message && strlen($item['inform'])) { $people = explode(',',$item['inform']); - foreach($people as $person) { - if(substr($person,0,4) === 'cid:') { + foreach ($people as $person) { + if (substr($person,0,4) === 'cid:') { $recipients[] = intval(substr($person,4)); $conversants[] = intval(substr($person,4)); - } - else { + } else { $url_recipients[] = substr($person,4); } } @@ -404,13 +404,14 @@ function notifier_run(&$argv, &$argc){ logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent[0]['author-link']." - Owner: ".$thr_parent[0]['owner-link'], LOGGER_DEBUG); // Send a salmon to the parent author - $r = q("SELECT `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''", + $r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''", dbesc(normalise_link($thr_parent[0]['author-link'])), intval($uid)); - if ($r) + if (dbm::is_result($r)) { $probed_contact = $r[0]; - else + } else { $probed_contact = probe_url($thr_parent[0]['author-link']); + } if ($probed_contact["notify"] != "") { logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]); @@ -421,10 +422,12 @@ function notifier_run(&$argv, &$argc){ $r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''", dbesc(normalise_link($thr_parent[0]['owner-link'])), intval($uid)); - if ($r) + if (dbm::is_result($r)) { $probed_contact = $r[0]; - else + } else { $probed_contact = probe_url($thr_parent[0]['owner-link']); + } + if ($probed_contact["notify"] != "") { logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]); $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; @@ -432,10 +435,10 @@ function notifier_run(&$argv, &$argc){ // Send a salmon notification to every person we mentioned in the post $arr = explode(',',$target_item['tag']); - foreach($arr as $x) { + foreach ($arr as $x) { //logger('Checking tag '.$x, LOGGER_DEBUG); $matches = null; - if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) { + if (preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) { $probed_contact = probe_url($matches[1]); if ($probed_contact["notify"] != "") { logger('Notify mentioned user '.$probed_contact["url"].': '.$probed_contact["notify"]); @@ -446,17 +449,19 @@ function notifier_run(&$argv, &$argc){ // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."')"; - } else + } else { $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."', '".NETWORK_DIASPORA."', '".NETWORK_MAIL."', '".NETWORK_MAIL2."')"; - } else + } + } else { $public_message = false; + } // If this is a public message and pubmail is set on the parent, include all your email contacts $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if(! $mail_disabled) { - if((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid'])) + if (! $mail_disabled) { + if ((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid'])) && (! strlen($target_item['deny_cid'])) && (! strlen($target_item['deny_gid'])) && (intval($target_item['pubmail']))) { $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s'", @@ -464,38 +469,40 @@ function notifier_run(&$argv, &$argc){ dbesc(NETWORK_MAIL) ); if (dbm::is_result($r)) { - foreach($r as $rr) + foreach ($r as $rr) { $recipients[] = $rr['id']; + } } } } - if($followup) + if ($followup) { $recip_str = implode(', ', $recipients_followup); - else + } else { $recip_str = implode(', ', $recipients); - - if ($relocate) + } + if ($relocate) { $r = $recipients_relocate; - else + } else { $r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra, dbesc($recip_str) ); + } $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval'))); // If we are using the worker we don't need a delivery interval - if (get_config("system", "worker")) + if (get_config("system", "worker")) { $interval = false; - + } // delivery loop if (dbm::is_result($r)) { - - foreach($r as $contact) { - if(!$contact['self']) { - if(($contact['network'] === NETWORK_DIASPORA) && ($public_message)) + foreach ($r as $contact) { + if (!$contact['self']) { + if (($contact['network'] === NETWORK_DIASPORA) && ($public_message)) { continue; + } q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d)", dbesc($cmd), intval($item_id), @@ -518,17 +525,18 @@ function notifier_run(&$argv, &$argc){ // When using the workerqueue, we don't need this functionality. $deliveries_per_process = intval(get_config('system','delivery_batch_count')); - if (($deliveries_per_process <= 0) OR get_config("system", "worker")) + if (($deliveries_per_process <= 0) OR get_config("system", "worker")) { $deliveries_per_process = 1; + } $this_batch = array(); - for($x = 0; $x < count($r); $x ++) { + for ($x = 0; $x < count($r); $x ++) { $contact = $r[$x]; - if($contact['self']) + if ($contact['self']) { continue; - + } logger("Deliver ".$target_item["guid"]." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG); // potentially more than one recipient. Start a new process and space them out a bit. @@ -536,26 +544,28 @@ function notifier_run(&$argv, &$argc){ $this_batch[] = $contact['id']; - if(count($this_batch) >= $deliveries_per_process) { + if (count($this_batch) >= $deliveries_per_process) { proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch); $this_batch = array(); - if($interval) + if ($interval) { @time_sleep_until(microtime(true) + (float) $interval); + } } continue; } // be sure to pick up any stragglers - if(count($this_batch)) + if (count($this_batch)) { proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch); + } } // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts // They are especially used for notifications to OStatus users that don't follow us. - if($slap && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) { - if(!get_config('system','dfrn_only')) { - foreach($url_recipients as $url) { + if ($slap && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) { + if (!get_config('system','dfrn_only')) { + foreach ($url_recipients as $url) { if ($url) { logger('notifier: urldelivery: ' . $url); $deliver_status = slapper($owner,$url,$slap); @@ -566,14 +576,15 @@ function notifier_run(&$argv, &$argc){ } - if($public_message) { + if ($public_message) { $r0 = array(); $r1 = array(); if ($diaspora_delivery) { - if (!$followup) + if (!$followup) { $r0 = Diaspora::relay_list(); + } $r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch` ORDER BY rand()", @@ -600,7 +611,7 @@ function notifier_run(&$argv, &$argc){ // throw everything into the queue in case we get killed foreach ($r as $rr) { - if((! $mail) && (! $fsuggest) && (! $followup)) { + if ((! $mail) && (! $fsuggest) && (! $followup)) { q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d) ON DUPLICATE KEY UPDATE `cmd` = '%s', `item` = %d, `contact` = %d", dbesc($cmd), intval($item_id), intval($rr['id']), @@ -614,16 +625,17 @@ function notifier_run(&$argv, &$argc){ // except for Diaspora batch jobs // Don't deliver to folks who have already been delivered to - if(($rr['network'] !== NETWORK_DIASPORA) && (in_array($rr['id'],$conversants))) { + if (($rr['network'] !== NETWORK_DIASPORA) && (in_array($rr['id'],$conversants))) { logger('notifier: already delivered id=' . $rr['id']); continue; } - if((! $mail) && (! $fsuggest) && (! $followup)) { + if ((! $mail) && (! $fsuggest) && (! $followup)) { logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]); proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$rr['id']); - if($interval) + if ($interval) { @time_sleep_until(microtime(true) + (float) $interval); + } } } } @@ -633,13 +645,14 @@ function notifier_run(&$argv, &$argc){ } // Notify PuSH subscribers (Used for OStatus distribution of regular posts) - if($push_notify AND strlen($hub)) { + if ($push_notify AND strlen($hub)) { $hubs = explode(',', $hub); - if(count($hubs)) { - foreach($hubs as $h) { + if (count($hubs)) { + foreach ($hubs as $h) { $h = trim($h); - if(! strlen($h)) + if (! strlen($h)) { continue; + } if ($h === '[internal]') { // Set push flag for PuSH subscribers to this topic, @@ -655,8 +668,9 @@ function notifier_run(&$argv, &$argc){ post_url($h,$params); logger('publish for item '.$item_id.' ' . $h . ' ' . $params . ' returned ' . $a->get_curl_code()); } - if(count($hubs) > 1) + if (count($hubs) > 1) { sleep(7); // try and avoid multiple hubs responding at precisely the same time + } } } @@ -666,8 +680,9 @@ function notifier_run(&$argv, &$argc){ logger('notifier: calling hooks', LOGGER_DEBUG); - if($normal_mode) + if ($normal_mode) { call_hooks('notifier_normal',$target_item); + } call_hooks('notifier_end',$target_item); From 65226778feda4a74b917a9b075cb51584be87d7d Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 9 Jan 2017 06:40:56 +0000 Subject: [PATCH 25/48] More standards --- include/notifier.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/notifier.php b/include/notifier.php index a56f1f89f..7bea239c6 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -192,8 +192,9 @@ function notifier_run(&$argv, &$argc){ // avoid race condition with deleting entries if ($items[0]['deleted']) { - foreach ($items as $item) + foreach ($items as $item) { $item['deleted'] = 1; + } } if ((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) { @@ -326,9 +327,11 @@ function notifier_run(&$argv, &$argc){ intval($uid), dbesc(NETWORK_DFRN) ); - if (dbm::is_result($r)) - foreach ($r as $rr) + if (dbm::is_result($r)) { + foreach ($r as $rr) { $recipients_followup[] = $rr['id']; + } + } } } logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG); From 16f0221e4c2b137e254853caac8acc7bf646c4d1 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 9 Jan 2017 09:37:37 +0000 Subject: [PATCH 26/48] DBClean now has a smaller limit/Query improvements --- include/acl_selectors.php | 22 +++++++++++----------- include/cron.php | 2 +- include/dbclean.php | 31 +++++++++++++++++++------------ view/theme/frio/theme.php | 8 ++++---- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index f6c4f947e..75a4985c8 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -135,7 +135,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { $o .= "\r\n"; $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' + WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' $sql_extra ORDER BY `name` ASC ", intval(local_user()) @@ -449,8 +449,8 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for editor mentions if ($type=='' || $type=='c'){ $r = q("SELECT COUNT(*) AS c FROM `contact` - WHERE `uid` = %d AND `self` = 0 - AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 + WHERE `uid` = %d AND NOT `self` + AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' $sql_extra2" , intval(local_user()) ); @@ -461,8 +461,8 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for Private Messages $r = q("SELECT COUNT(*) AS c FROM `contact` - WHERE `uid` = %d AND `self` = 0 - AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 + WHERE `uid` = %d AND NOT `self` + AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `network` IN ('%s','%s','%s') $sql_extra2" , intval(local_user()), dbesc(NETWORK_DFRN), @@ -477,8 +477,8 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for Contacts $r = q("SELECT COUNT(*) AS c FROM `contact` - WHERE `uid` = %d AND `self` = 0 - AND `pending` = 0 $sql_extra2" , + WHERE `uid` = %d AND NOT `self` + AND NOT `pending` $sql_extra2" , intval(local_user()) ); $contact_count = (int)$r[0]['c']; @@ -525,7 +525,7 @@ function acl_lookup(&$a, $out_type = 'json') { if ($type==''){ $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' + WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' AND NOT (`network` IN ('%s', '%s')) $sql_extra2 ORDER BY `name` ASC ", @@ -536,7 +536,7 @@ function acl_lookup(&$a, $out_type = 'json') { elseif ($type=='c'){ $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' + WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' AND NOT (`network` IN ('%s')) $sql_extra2 ORDER BY `name` ASC ", @@ -546,7 +546,7 @@ function acl_lookup(&$a, $out_type = 'json') { } elseif($type == 'm') { $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 + WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `network` IN ('%s','%s','%s') $sql_extra2 ORDER BY `name` ASC ", diff --git a/include/cron.php b/include/cron.php index e98239b82..97744ed27 100644 --- a/include/cron.php +++ b/include/cron.php @@ -128,7 +128,7 @@ function cron_run(&$argv, &$argc){ proc_run(PRIORITY_LOW, 'include/expire.php'); - proc_run(PRIORITY_LOW, 'include/dbclean.php'); + proc_run(PRIORITY_MEDIUM, 'include/dbclean.php'); cron_update_photo_albums(); } diff --git a/include/dbclean.php b/include/dbclean.php index 29c417308..c80e5a3be 100644 --- a/include/dbclean.php +++ b/include/dbclean.php @@ -23,8 +23,8 @@ function dbclean_run(&$argv, &$argc) { unset($db_host, $db_user, $db_pass, $db_data); } - load_config('config'); - load_config('system'); + Config::load('config'); + Config::load('system'); if (!Config::get('system', 'dbclean', false)) { return; @@ -36,7 +36,7 @@ function dbclean_run(&$argv, &$argc) { $stage = 0; } - if (get_config("system", "worker") AND ($stage == 0)) { + if (Config::get("system", "worker") AND ($stage == 0)) { proc_run(PRIORITY_LOW, 'include/dbclean.php', 1); proc_run(PRIORITY_LOW, 'include/dbclean.php', 2); proc_run(PRIORITY_LOW, 'include/dbclean.php', 3); @@ -57,11 +57,18 @@ function remove_orphans($stage = 0) { $count = 0; + // With activated worker we split the deletion in many small tasks + if (Config::get("system", "worker")) { + $limit = 1000; + } else { + $limit = 10000; + } + if (($stage == 1) OR ($stage == 0)) { logger("Deleting old global item entries from item table without user copy"); if ($db->q("SELECT `id` FROM `item` WHERE `uid` = 0 AND NOT EXISTS (SELECT `guid` FROM `item` AS `i` WHERE `item`.`guid` = `i`.`guid` AND `i`.`uid` != 0) - AND `received` < UTC_TIMESTAMP() - INTERVAL 90 DAY LIMIT 10000", true)) { + AND `received` < UTC_TIMESTAMP() - INTERVAL 90 DAY LIMIT ".intval($limit), true)) { $count = $db->num_rows(); logger("found global item orphans: ".$count); while ($orphan = $db->qfetch()) { @@ -74,7 +81,7 @@ function remove_orphans($stage = 0) { if (($stage == 2) OR ($stage == 0)) { logger("Deleting items without parents"); - if ($db->q("SELECT `id` FROM `item` WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`) LIMIT 10000", true)) { + if ($db->q("SELECT `id` FROM `item` WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`) LIMIT ".intval($limit), true)) { $count = $db->num_rows(); logger("found item orphans without parents: ".$count); while ($orphan = $db->qfetch()) { @@ -87,7 +94,7 @@ function remove_orphans($stage = 0) { if (($stage == 3) OR ($stage == 0)) { logger("Deleting orphaned data from thread table"); - if ($db->q("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`)", true)) { + if ($db->q("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`) LIMIT ".intval($limit), true)) { $count = $db->num_rows(); logger("found thread orphans: ".$count); while ($orphan = $db->qfetch()) { @@ -100,7 +107,7 @@ function remove_orphans($stage = 0) { if (($stage == 4) OR ($stage == 0)) { logger("Deleting orphaned data from notify table"); - if ($db->q("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`)", true)) { + if ($db->q("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`) LIMIT ".intval($limit), true)) { $count = $db->num_rows(); logger("found notify orphans: ".$count); while ($orphan = $db->qfetch()) { @@ -113,7 +120,7 @@ function remove_orphans($stage = 0) { if (($stage == 5) OR ($stage == 0)) { logger("Deleting orphaned data from notify-threads table"); - if ($db->q("SELECT `id` FROM `notify-threads` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `notify-threads`.`master-parent-item`)", true)) { + if ($db->q("SELECT `id` FROM `notify-threads` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `notify-threads`.`master-parent-item`) LIMIT ".intval($limit), true)) { $count = $db->num_rows(); logger("found notify-threads orphans: ".$count); while ($orphan = $db->qfetch()) { @@ -127,7 +134,7 @@ function remove_orphans($stage = 0) { if (($stage == 6) OR ($stage == 0)) { logger("Deleting orphaned data from sign table"); - if ($db->q("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`)", true)) { + if ($db->q("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`) LIMIT ".intval($limit), true)) { $count = $db->num_rows(); logger("found sign orphans: ".$count); while ($orphan = $db->qfetch()) { @@ -141,7 +148,7 @@ function remove_orphans($stage = 0) { if (($stage == 7) OR ($stage == 0)) { logger("Deleting orphaned data from term table"); - if ($db->q("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`)", true)) { + if ($db->q("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`) LIMIT ".intval($limit), true)) { $count = $db->num_rows(); logger("found term orphans: ".$count); while ($orphan = $db->qfetch()) { @@ -153,8 +160,8 @@ function remove_orphans($stage = 0) { } // Call it again if not all entries were purged - if (($stage != 0) AND ($count > 0) AND get_config("system", "worker")) { - proc_run(PRIORITY_LOW, 'include/dbclean.php'); + if (($stage != 0) AND ($count > 0) AND Config::get("system", "worker")) { + proc_run(PRIORITY_MEDIUM, 'include/dbclean.php'); } } diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index f9cbf79a6..a2fde7b25 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -219,8 +219,8 @@ function frio_remote_nav($a,&$nav) { // empty the server url for local user because we won't need it $server_url = ''; // user info - $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self` = 1", intval($a->user['uid'])); - + $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self`", intval($a->user['uid'])); + $r[0]['photo'] = (dbm::is_result($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg"); $r[0]['name'] = $a->user['username']; @@ -298,7 +298,7 @@ function frio_acl_lookup($a, &$results) { $r = q("SELECT COUNT(*) AS `total` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ", + WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra2 ", intval($_SESSION['uid'])); if (dbm::is_result($r)) { $total = $r[0]["total"]; @@ -306,7 +306,7 @@ function frio_acl_lookup($a, &$results) { $sql_extra3 = unavailable_networks(); - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT 100 ", + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT 100 ", intval($_SESSION['uid']) ); From 623479a346ee6524e9b32e731651a6db12da330b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jan 2017 23:06:08 +1100 Subject: [PATCH 27/48] Normalize App parameter declaration (view folder) --- view/theme/duepuntozero/config.php | 12 +++---- view/theme/duepuntozero/theme.php | 6 ++-- view/theme/frio/config.php | 10 +++--- view/theme/frio/php/frio_boot.php | 32 +++++++++---------- view/theme/frio/theme.php | 50 +++++++++++++++--------------- view/theme/frost-mobile/theme.php | 4 +-- view/theme/frost/theme.php | 8 ++--- view/theme/quattro/config.php | 10 +++--- view/theme/quattro/theme.php | 2 +- view/theme/smoothly/theme.php | 6 ++-- view/theme/vier/config.php | 10 +++--- view/theme/vier/theme.php | 2 +- 12 files changed, 76 insertions(+), 76 deletions(-) diff --git a/view/theme/duepuntozero/config.php b/view/theme/duepuntozero/config.php index 48c9c8709..381b06716 100644 --- a/view/theme/duepuntozero/config.php +++ b/view/theme/duepuntozero/config.php @@ -3,7 +3,7 @@ * Theme settings */ -function theme_content(App &$a){ +function theme_content(App $a) { if (!local_user()) { return; } @@ -14,7 +14,7 @@ function theme_content(App &$a){ return clean_form($a, $colorset, $user); } -function theme_post(App &$a){ +function theme_post(App $a) { if (! local_user()) { return; } @@ -24,23 +24,23 @@ function theme_post(App &$a){ } } -function theme_admin(App &$a){ +function theme_admin(App $a) { $colorset = get_config( 'duepuntozero', 'colorset'); $user = false; return clean_form($a, $colorset, $user); } -function theme_admin_post(App &$a){ +function theme_admin_post(App $a) { if (isset($_POST['duepuntozero-settings-submit'])){ set_config('duepuntozero', 'colorset', $_POST['duepuntozero_colorset']); } } /// @TODO $a is no longer used -function clean_form(&$a, &$colorset, $user){ +function clean_form(App $a, &$colorset, $user) { $colorset = array( - 'default' =>t('default'), + 'default' =>t('default'), 'greenzero' =>t('greenzero'), 'purplezero' =>t('purplezero'), 'easterbunny' =>t('easterbunny'), diff --git a/view/theme/duepuntozero/theme.php b/view/theme/duepuntozero/theme.php index bf1d031de..7d3c22469 100644 --- a/view/theme/duepuntozero/theme.php +++ b/view/theme/duepuntozero/theme.php @@ -1,6 +1,6 @@ page['htmlhead'] .= <<< EOT '; $a->page['htmlhead'] .= '';; } diff --git a/view/theme/smoothly/theme.php b/view/theme/smoothly/theme.php index 32c48fffa..7e8744f0d 100644 --- a/view/theme/smoothly/theme.php +++ b/view/theme/smoothly/theme.php @@ -10,7 +10,7 @@ * Screenshot: Screenshot */ -function smoothly_init(App &$a) { +function smoothly_init(App $a) { set_template_engine($a, 'smarty3'); $cssFile = null; @@ -20,7 +20,7 @@ $a->page['htmlhead'] .= <<< EOT