Improved indexes, avoiding SQL errors, improving speed
This commit is contained in:
parent
d2360d14ed
commit
92a8a399de
|
@ -78,7 +78,7 @@ class Item
|
|||
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
|
||||
'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network',
|
||||
'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network', 'owner-contact-type',
|
||||
'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type', 'causer-network',
|
||||
'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
|
||||
'writable', 'self', 'cid', 'alias',
|
||||
|
@ -2513,12 +2513,11 @@ class Item
|
|||
* Body is preserved to avoid side-effects as we modify it just-in-time for spoilers and private image links
|
||||
*
|
||||
* @param array $item
|
||||
* @param bool $update
|
||||
*
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @todo Remove reference, simply return "rendered-html" and "rendered-hash"
|
||||
*/
|
||||
public static function putInCache(&$item, $update = false)
|
||||
public static function putInCache(&$item)
|
||||
{
|
||||
// Save original body to prevent addons to modify it
|
||||
$body = $item['body'];
|
||||
|
@ -2542,17 +2541,8 @@ class Item
|
|||
$item['rendered-hash'] = $hook_data['rendered-hash'];
|
||||
unset($hook_data);
|
||||
|
||||
// Force an update if the generated values differ from the existing ones
|
||||
if ($rendered_hash != $item['rendered-hash']) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
// Only compare the HTML when we forcefully ignore the cache
|
||||
if (DI::config()->get('system', 'ignore_cache') && ($rendered_html != $item['rendered-html'])) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if ($update && !empty($item['id'])) {
|
||||
// Update if the generated values differ from the existing ones
|
||||
if ((($rendered_hash != $item['rendered-hash']) || ($rendered_html != $item['rendered-html'])) && !empty($item['id'])) {
|
||||
self::update(
|
||||
[
|
||||
'rendered-html' => $item['rendered-html'],
|
||||
|
@ -2640,15 +2630,7 @@ class Item
|
|||
unset($hook_data);
|
||||
}
|
||||
|
||||
// Update the cached values if there is no "zrl=..." on the links.
|
||||
$update = (!Session::isAuthenticated() && ($item["uid"] == 0));
|
||||
|
||||
// Or update it if the current viewer is the intented viewer.
|
||||
if (($item["uid"] == local_user()) && ($item["uid"] != 0)) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
self::putInCache($item, $update);
|
||||
self::putInCache($item);
|
||||
$s = $item["rendered-html"];
|
||||
|
||||
$hook_data = [
|
||||
|
|
|
@ -58,18 +58,14 @@ class Nodeinfo
|
|||
$config->set('nodeinfo', 'active_users_monthly', $userStats['active_users_monthly']);
|
||||
$config->set('nodeinfo', 'active_users_weekly', $userStats['active_users_weekly']);
|
||||
|
||||
$logger->debug('user statistics', $userStats);
|
||||
$logger->info('user statistics', $userStats);
|
||||
|
||||
$items = DBA::p("SELECT COUNT(*) AS `total`, `gravity` FROM `post-view` WHERE `origin` AND NOT `deleted` AND `uid` != 0 AND `gravity` IN (?, ?) GROUP BY `gravity`",
|
||||
GRAVITY_PARENT, GRAVITY_COMMENT);
|
||||
while ($item = DBA::fetch($items)) {
|
||||
if ($item['gravity'] == GRAVITY_PARENT) {
|
||||
$config->set('nodeinfo', 'local_posts', $item['total']);
|
||||
} elseif ($item['gravity'] == GRAVITY_COMMENT) {
|
||||
$config->set('nodeinfo', 'local_comments', $item['total']);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
$posts = DBA::count('post-thread', ["EXISTS(SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin` AND `uri-id` = `post-thread`.`uri-id`)"]);
|
||||
$comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND EXISTS(SELECT `uri-id` FROM `post-user` WHERE `origin` AND `uri-id` = `post`.`uri-id`)", GRAVITY_COMMENT]);
|
||||
$config->set('nodeinfo', 'local_posts', $posts);
|
||||
$config->set('nodeinfo', 'local_comments', $comments);
|
||||
|
||||
$logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Model;
|
|||
|
||||
use BadMethodCallException;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
|
@ -421,7 +422,7 @@ class Post
|
|||
{
|
||||
$affected = 0;
|
||||
|
||||
Logger::info('Start Update', ['fields' => $fields, 'condition' => $condition]);
|
||||
Logger::debug('Start Update', ['fields' => $fields, 'condition' => $condition, 'uid' => local_user(),'callstack' => System::callstack(10)]);
|
||||
|
||||
// Don't allow changes to fields that are responsible for the relation between the records
|
||||
unset($fields['id']);
|
||||
|
|
|
@ -315,13 +315,13 @@ class Community extends BaseModule
|
|||
{
|
||||
if (self::$content == 'local') {
|
||||
if (!is_null(self::$accountType)) {
|
||||
$condition = ["`wall` AND `origin` AND `private` = ? AND `owner`.`contact-type` = ?", Item::PUBLIC, self::$accountType];
|
||||
$condition = ["`wall` AND `origin` AND `private` = ? AND `owner-contact-type` = ?", Item::PUBLIC, self::$accountType];
|
||||
} else {
|
||||
$condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC];
|
||||
}
|
||||
} elseif (self::$content == 'global') {
|
||||
if (!is_null(self::$accountType)) {
|
||||
$condition = ["`uid` = ? AND `private` = ? AND `owner`.`contact-type` = ?", 0, Item::PUBLIC, self::$accountType];
|
||||
$condition = ["`uid` = ? AND `private` = ? AND `owner-contact-type` = ?", 0, Item::PUBLIC, self::$accountType];
|
||||
} else {
|
||||
$condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC];
|
||||
}
|
||||
|
|
|
@ -181,9 +181,9 @@ class Status extends BaseProfile
|
|||
|
||||
$condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
|
||||
(`gravity` = ? AND `vid` = ? AND `origin` AND `thr-parent-id` IN
|
||||
(SELECT `uri-id` FROM `post-view` AS `i`
|
||||
(SELECT `uri-id` FROM `post-view`
|
||||
WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?) AND `uid` IN (?, ?)
|
||||
AND `i`.`uri-id` = `thr-parent-id`)))",
|
||||
AND `uri-id` = `thr-parent-id`)))",
|
||||
GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT,
|
||||
Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS,
|
||||
0, $a->profile['uid']]);
|
||||
|
|
|
@ -81,7 +81,7 @@ class Profile extends BaseModule
|
|||
}
|
||||
|
||||
$items_stmt = DBA::p(
|
||||
"SELECT DISTINCT(`parent-uri-id`) AS `uri-id`, `created` FROM `post-view`
|
||||
"SELECT DISTINCT(`parent-uri-id`) AS `uri-id`, MAX(`created`), MAX(`received`) FROM `post-view`
|
||||
WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
|
||||
AND `visible` AND (NOT `deleted` OR `gravity` = ?)
|
||||
AND `wall` $sql_extra4 $sql_extra
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1404);
|
||||
define('DB_UPDATE_VERSION', 1405);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -1002,7 +1002,6 @@ return [
|
|||
"author-id" => ["author-id"],
|
||||
"causer-id" => ["causer-id"],
|
||||
"vid" => ["vid"],
|
||||
"received" => ["received"],
|
||||
]
|
||||
],
|
||||
"post-category" => [
|
||||
|
@ -1110,7 +1109,6 @@ return [
|
|||
"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" => ""],
|
||||
"changed" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date that something in the conversation changed, indicating clients should fetch the conversation again"],
|
||||
"commented" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""]
|
||||
],
|
||||
"indexes" => [
|
||||
|
@ -1160,26 +1158,24 @@ return [
|
|||
"PRIMARY" => ["id"],
|
||||
"uid_uri-id" => ["UNIQUE", "uid", "uri-id"],
|
||||
"uri-id" => ["uri-id"],
|
||||
"contact-id" => ["contact-id"],
|
||||
"psid" => ["psid"],
|
||||
"uid_hidden" => ["uid", "hidden"],
|
||||
"event-id" => ["event-id"],
|
||||
"uid_wall" => ["uid", "wall"],
|
||||
"parent-uri-id_uid" => ["parent-uri-id", "uid"],
|
||||
"parent-uri-id" => ["parent-uri-id"],
|
||||
"thr-parent-id" => ["thr-parent-id"],
|
||||
"external-id" => ["external-id"],
|
||||
"owner-id" => ["owner-id"],
|
||||
"author-id_uid" => ["author-id", "uid"],
|
||||
"author-id" => ["author-id"],
|
||||
"causer-id" => ["causer-id"],
|
||||
"vid" => ["vid"],
|
||||
"uid_received" => ["uid", "received"],
|
||||
"contact-id" => ["contact-id"],
|
||||
"event-id" => ["event-id"],
|
||||
"psid" => ["psid"],
|
||||
"author-id_uid" => ["author-id", "uid"],
|
||||
"author-id_received" => ["author-id", "received"],
|
||||
"parent-uri-id_uid" => ["parent-uri-id", "uid"],
|
||||
"uid_hidden" => ["uid", "hidden"],
|
||||
"uid_contactid" => ["uid", "contact-id"],
|
||||
"uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
|
||||
"uid_network_received" => ["uid", "network", "received"],
|
||||
"uid_contactid_received" => ["uid", "contact-id", "received"],
|
||||
"authorid_received" => ["author-id", "received"],
|
||||
"uid_unseen" => ["uid", "unseen"],
|
||||
"uid_unseen_wall" => ["uid", "unseen", "wall"],
|
||||
"uid_eventid" => ["uid", "event-id"],
|
||||
"psid_wall" => ["psid", "wall"],
|
||||
],
|
||||
],
|
||||
"post-thread-user" => [
|
||||
|
@ -1211,30 +1207,21 @@ return [
|
|||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["uid", "uri-id"],
|
||||
"uid_wall" => ["uid", "wall"],
|
||||
"uid_pinned" => ["uid", "pinned"],
|
||||
"uri-id" => ["uri-id"],
|
||||
"owner-id" => ["owner-id"],
|
||||
"author-id" => ["author-id"],
|
||||
"causer-id" => ["causer-id"],
|
||||
"uid" => ["uid"],
|
||||
"contact-id" => ["contact-id"],
|
||||
"psid" => ["psid"],
|
||||
"post-user-id" => ["post-user-id"],
|
||||
"owner-id" => ["owner-id"],
|
||||
"causer-id" => ["causer-id"],
|
||||
"uid_received" => ["uid", "received"],
|
||||
"uid_commented" => ["uid", "commented"],
|
||||
"uid_changed" => ["uid", "changed"],
|
||||
"uid_contact-id" => ["uid", "contact-id", "received"],
|
||||
"uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
|
||||
"uid_network_received" => ["uid", "network", "received"],
|
||||
"uid_network_commented" => ["uid", "network", "commented"],
|
||||
"uid_contact-id_received" => ["uid", "contact-id", "received"],
|
||||
"author-id_received" => ["author-id", "received"],
|
||||
"uid_wall_changed" => ["uid", "wall", "changed"],
|
||||
"uid_unseen_wall" => ["uid", "unseen", "wall"],
|
||||
"mention_uid" => ["mention", "uid"],
|
||||
"psid_wall" => ["psid", "wall"],
|
||||
"received" => ["received"],
|
||||
"commented" => ["commented"],
|
||||
"changed" => ["changed"],
|
||||
"received" => ["received"],
|
||||
"author-id_received" => ["author-id", "received"],
|
||||
"uid_pinned" => ["uid", "pinned"],
|
||||
"uid_commented" => ["uid", "commented"],
|
||||
"mention_uid" => ["mention", "uid"],
|
||||
"uid_mention" => ["uid", "mention"],
|
||||
]
|
||||
],
|
||||
"post-user-notification" => [
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
"owner-network" => ["owner", "network"],
|
||||
"owner-blocked" => ["owner", "blocked"],
|
||||
"owner-hidden" => ["owner", "hidden"],
|
||||
"owner-contact-type" => ["owner", "contact-type"],
|
||||
"causer-id" => ["post-user", "causer-id"],
|
||||
"causer-link" => ["causer", "url"],
|
||||
"causer-addr" => ["causer", "addr"],
|
||||
|
@ -289,6 +290,7 @@
|
|||
"owner-network" => ["owner", "network"],
|
||||
"owner-blocked" => ["owner", "blocked"],
|
||||
"owner-hidden" => ["owner", "hidden"],
|
||||
"owner-contact-type" => ["owner", "contact-type"],
|
||||
"causer-id" => ["post-thread-user", "causer-id"],
|
||||
"causer-link" => ["causer", "url"],
|
||||
"causer-addr" => ["causer", "addr"],
|
||||
|
|
Loading…
Reference in New Issue
Block a user