Fix slow queries
This commit is contained in:
parent
0277c55c43
commit
5f48d6497e
6 changed files with 47 additions and 17 deletions
|
@ -1959,7 +1959,7 @@ class Contact
|
|||
}
|
||||
|
||||
// If Probe::uri fails the network code will be different ("feed" or "unkn")
|
||||
if (in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]) && ($ret['network'] != $contact['network'])) {
|
||||
if (($ret['network'] == Protocol::PHANTOM) || (($ret['network'] == Protocol::FEED) && ($ret['network'] != $contact['network']))) {
|
||||
self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => true, 'last-update' => $updated, 'failure_update' => $updated]);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -970,6 +970,10 @@ class Item
|
|||
unset($item['event-id']);
|
||||
}
|
||||
|
||||
if (empty($item['causer-id'])) {
|
||||
unset($item['causer-id']);
|
||||
}
|
||||
|
||||
Post::insert($item['uri-id'], $item);
|
||||
|
||||
if ($item['gravity'] == GRAVITY_PARENT) {
|
||||
|
|
|
@ -285,7 +285,7 @@ class Post
|
|||
$condition = DBA::mergeConditions($condition,
|
||||
["`visible` AND NOT `deleted`
|
||||
AND NOT `author-blocked` AND NOT `owner-blocked`
|
||||
AND (NOT `causer-blocked` OR `causer-id` = ?) AND NOT `contact-blocked`
|
||||
AND (NOT `causer-blocked` OR `causer-id` = ? OR `causer-id` IS NULL) AND NOT `contact-blocked`
|
||||
AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
|
||||
OR `self` OR `gravity` != ? OR `contact-uid` = ?)
|
||||
AND NOT EXISTS (SELECT `uri-id` FROM `post-user` WHERE `hidden` AND `uri-id` = `" . $view . "`.`uri-id` AND `uid` = ?)
|
||||
|
|
|
@ -49,16 +49,27 @@ class UpdateContacts
|
|||
return;
|
||||
}
|
||||
|
||||
// Add every contact our system interacted with and hadn't been updated for a week if unarchived
|
||||
// or for a month if archived.
|
||||
$condition = DBA::mergeConditions($base_condition, ["(`id` IN (SELECT `author-id` FROM `post-user`) OR
|
||||
`id` IN (SELECT `owner-id` FROM `post-user`) OR `id` IN (SELECT `causer-id` FROM `post-user`) OR
|
||||
`id` IN (SELECT `cid` FROM `post-tag`) OR `id` IN (SELECT `cid` FROM `user-contact`) OR `uid` != ?) AND
|
||||
(`last-update` < ? OR (NOT `archive` AND `last-update` < ?))",
|
||||
$condition = DBA::mergeConditions($base_condition,
|
||||
["`uid` != ? AND (`last-update` < ? OR (NOT `archive` AND `last-update` < ?))",
|
||||
0, DateTimeFormat::utc('now - 1 month'), DateTimeFormat::utc('now - 1 week')]);
|
||||
Logger::info('Updatable interacting federated contacts', ['count' => DBA::count('contact', $condition)]);
|
||||
$ids = self::getContactsToUpdate($condition, [], $limit);
|
||||
Logger::info('Fetched interacting federated contacts', ['count' => count($ids)]);
|
||||
Logger::info('Fetched federated user contacts', ['count' => count($ids)]);
|
||||
|
||||
$conditions = ["`id` IN (SELECT `author-id` FROM `post-user`)", "`id` IN (SELECT `owner-id` FROM `post-user`)",
|
||||
"`id` IN (SELECT `causer-id` FROM `post-user`)", "`id` IN (SELECT `cid` FROM `post-tag`)",
|
||||
"`id` IN (SELECT `cid` FROM `user-contact`)"];
|
||||
|
||||
foreach ($conditions as $contact_condition) {
|
||||
$condition = DBA::mergeConditions($base_condition,
|
||||
[$contact_condition . " AND (`last-update` < ? OR (NOT `archive` AND `last-update` < ?))",
|
||||
DateTimeFormat::utc('now - 1 month'), DateTimeFormat::utc('now - 1 week')]);
|
||||
$ids = self::getContactsToUpdate($condition, $ids, $limit);
|
||||
Logger::info('Fetched interacting federated contacts', ['count' => count($ids), 'condition' => $contact_condition]);
|
||||
}
|
||||
|
||||
if (count($ids) > $limit) {
|
||||
$ids = array_slice($ids, 0, $limit, true);
|
||||
}
|
||||
|
||||
if (!DI::config()->get('system', 'update_active_contacts')) {
|
||||
// Add every contact (mostly failed ones) that hadn't been updated for six months
|
||||
|
@ -66,7 +77,6 @@ class UpdateContacts
|
|||
$condition = DBA::mergeConditions($base_condition,
|
||||
["(`last-update` < ? OR (NOT `archive` AND `last-update` < ?))",
|
||||
DateTimeFormat::utc('now - 6 month'), DateTimeFormat::utc('now - 1 month')]);
|
||||
Logger::info('Updatable federated contacts', ['count' => DBA::count('contact', $condition)]);
|
||||
$previous = count($ids);
|
||||
$ids = self::getContactsToUpdate($condition, $ids, $limit - $previous);
|
||||
Logger::info('Fetched federated contacts', ['count' => count($ids) - $previous]);
|
||||
|
@ -93,7 +103,7 @@ class UpdateContacts
|
|||
{
|
||||
$contacts = DBA::select('contact', ['id'], $condition, ['limit' => $limit, 'order' => ['last-update']]);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
$ids[] = $contact['id'];
|
||||
$ids[$contact['id']] = $contact['id'];
|
||||
}
|
||||
DBA::close($contacts);
|
||||
return $ids;
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1406);
|
||||
define('DB_UPDATE_VERSION', 1407);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -993,7 +993,7 @@ return [
|
|||
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
|
||||
"owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
|
||||
"author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
|
||||
"causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
|
||||
"causer-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
|
||||
"post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
|
||||
"vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
|
||||
"private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"],
|
||||
|
@ -1114,7 +1114,7 @@ return [
|
|||
"uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
|
||||
"owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item owner"],
|
||||
"author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item author"],
|
||||
"causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
|
||||
"causer-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
|
||||
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
||||
"received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
||||
|
@ -1146,7 +1146,7 @@ return [
|
|||
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
|
||||
"owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
|
||||
"author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
|
||||
"causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
|
||||
"causer-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
|
||||
"post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
|
||||
"vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
|
||||
"private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"],
|
||||
|
@ -1194,7 +1194,7 @@ return [
|
|||
"uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
|
||||
"owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item owner"],
|
||||
"author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item author"],
|
||||
"causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
|
||||
"causer-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
|
||||
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
||||
"received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
||||
|
|
16
update.php
16
update.php
|
@ -885,3 +885,19 @@ function update_1404()
|
|||
DBA::update('workerqueue', ['parameter' => json_encode($parameters)], ['id' => $task['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
function update_1407()
|
||||
{
|
||||
if (!DBA::e("UPDATE `post` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
|
||||
return Update::FAILED;
|
||||
}
|
||||
if (!DBA::e("UPDATE `post-user` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
|
||||
return Update::FAILED;
|
||||
}
|
||||
if (!DBA::e("UPDATE `post-thread` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
|
||||
return Update::FAILED;
|
||||
}
|
||||
if (!DBA::e("UPDATE `post-thread-user` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
|
||||
return Update::FAILED;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue