Merge pull request #9938 from annando/database-issues

Fix several database issues
This commit is contained in:
Hypolite Petovan 2021-02-16 18:34:58 -05:00 committed by GitHub
commit a5cce36c44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 30 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.03-dev (Red Hot Poker) -- Friendica 2021.03-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1400 -- DB_UPDATE_VERSION 1401
-- ------------------------------------------ -- ------------------------------------------
@ -889,7 +889,7 @@ CREATE TABLE IF NOT EXISTS `notify` (
`msg` mediumtext COMMENT '', `msg` mediumtext COMMENT '',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id', `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
`link` varchar(255) NOT NULL DEFAULT '' COMMENT '', `link` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`iid` int unsigned COMMENT 'item.id', `iid` int unsigned COMMENT '',
`parent` int unsigned COMMENT '', `parent` int unsigned COMMENT '',
`uri-id` int unsigned COMMENT 'Item-uri id of the related post', `uri-id` int unsigned COMMENT 'Item-uri id of the related post',
`parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post', `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
@ -915,17 +915,15 @@ CREATE TABLE IF NOT EXISTS `notify` (
CREATE TABLE IF NOT EXISTS `notify-threads` ( CREATE TABLE IF NOT EXISTS `notify-threads` (
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID', `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
`notify-id` int unsigned NOT NULL DEFAULT 0 COMMENT '', `notify-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`master-parent-item` int unsigned COMMENT '', `master-parent-item` int unsigned COMMENT 'Deprecated',
`master-parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post', `master-parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
`parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '', `parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', `receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
INDEX `master-parent-item` (`master-parent-item`),
INDEX `master-parent-uri-id` (`master-parent-uri-id`), INDEX `master-parent-uri-id` (`master-parent-uri-id`),
INDEX `receiver-uid` (`receiver-uid`), INDEX `receiver-uid` (`receiver-uid`),
INDEX `notify-id` (`notify-id`), INDEX `notify-id` (`notify-id`),
FOREIGN KEY (`notify-id`) REFERENCES `notify` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, FOREIGN KEY (`notify-id`) REFERENCES `notify` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`master-parent-item`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`master-parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, FOREIGN KEY (`master-parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT=''; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
@ -1748,7 +1746,6 @@ DROP VIEW IF EXISTS `post-thread-view`;
CREATE VIEW `post-thread-view` AS SELECT CREATE VIEW `post-thread-view` AS SELECT
`post-user`.`id` AS `id`, `post-user`.`id` AS `id`,
`item`.`id` AS `item-id`, `item`.`id` AS `item-id`,
`post-user`.`id` AS `iid`,
`post-user`.`id` AS `post-user-id`, `post-user`.`id` AS `post-user-id`,
`post-thread-user`.`uid` AS `uid`, `post-thread-user`.`uid` AS `uid`,
`parent-post`.`id` AS `parent`, `parent-post`.`id` AS `parent`,

View file

@ -46,7 +46,7 @@ function editpost_content(App $a)
} }
$fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', $fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'type', 'body', 'title', 'uri-id', 'wall', 'post-type', 'guid']; 'body', 'title', 'uri-id', 'wall', 'post-type', 'guid'];
$item = Post::selectFirstForUser(local_user(), $fields, ['id' => $post_id, 'uid' => local_user()]); $item = Post::selectFirstForUser(local_user(), $fields, ['id' => $post_id, 'uid' => local_user()]);

View file

@ -224,7 +224,7 @@ class Post
$selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST); $selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
if ($view == 'post-thread-view') { if ($view == 'post-thread-view') {
$selected = array_merge($selected, ['ignored', 'iid']); $selected = array_merge($selected, ['ignored']);
} }
} }

View file

@ -68,9 +68,12 @@ class Profile extends BaseModule
$last_updated = $last_updated_array[$last_updated_key] ?? 0; $last_updated = $last_updated_array[$last_updated_key] ?? 0;
// If the page user is the owner of the page we should query for unseen if ($_GET['force'] && !empty($_GET['item'])) {
// items. Otherwise use a timestamp of the last succesful update request. // When the parent is provided, we only fetch this
if ($is_owner || !$last_updated) { $sql_extra4 = " AND `parent` = " . intval($_GET['item']);
} elseif ($is_owner || !$last_updated) {
// If the page user is the owner of the page we should query for unseen
// items. Otherwise use a timestamp of the last succesful update request.
$sql_extra4 = " AND `unseen`"; $sql_extra4 = " AND `unseen`";
} else { } else {
$gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated); $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);

View file

@ -32,6 +32,10 @@ use Friendica\Model\Post;
*/ */
class RemoveContact { class RemoveContact {
public static function execute($id) { public static function execute($id) {
if (empty($id)) {
return;
}
// Only delete if the contact is to be deleted // Only delete if the contact is to be deleted
$contact = DBA::selectFirst('contact', ['uid'], ['deleted' => true, 'id' => $id]); $contact = DBA::selectFirst('contact', ['uid'], ['deleted' => true, 'id' => $id]);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
@ -47,20 +51,31 @@ class RemoveContact {
} else { } else {
$condition = ['uid' => $contact['uid'], 'contact-id' => $id]; $condition = ['uid' => $contact['uid'], 'contact-id' => $id];
} }
do { if (DBStructure::existsTable('item')) {
$items = Post::select(['item-id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]); do {
while ($item = Post::fetch($items)) { $items = Post::select(['item-id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]);
Logger::info('Delete removed contact item', ['id' => $item['item-id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]); while ($item = Post::fetch($items)) {
if (DBStructure::existsTable('item')) { Logger::info('Delete removed contact item', ['id' => $item['item-id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
DBA::delete('item', ['id' => $item['item-id']]); DBA::delete('item', ['id' => $item['item-id']]);
} }
Post::delete(['uri-id' => $item['uri-id']]); DBA::close($items);
Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]); } while (Post::exists($condition));
Post\Thread::delete(['uri-id' => $item['uri-id']]); }
Post\User::delete(['id' => $item['post-user-id']]);
} Post\User::delete(['author-id' => $id]);
DBA::close($items); Post\User::delete(['owner-id' => $id]);
} while (Post::exists($condition)); Post\User::delete(['causer-id' => $id]);
Post\User::delete(['contact-id' => $id]);
Post\ThreadUser::delete(['author-id' => $id]);
Post\ThreadUser::delete(['owner-id' => $id]);
Post\ThreadUser::delete(['causer-id' => $id]);
Post\ThreadUser::delete(['contact-id' => $id]);
Post\Thread::delete(['author-id' => $id]);
Post\Thread::delete(['owner-id' => $id]);
Post\Thread::delete(['causer-id' => $id]);
Post::delete(['author-id' => $id]);
Post::delete(['owner-id' => $id]);
Post::delete(['causer-id' => $id]);
Photo::delete(['contact-id' => $id]); Photo::delete(['contact-id' => $id]);
$ret = DBA::delete('contact', ['id' => $id]); $ret = DBA::delete('contact', ['id' => $id]);

View file

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1400); define('DB_UPDATE_VERSION', 1401);
} }
return [ return [
@ -951,8 +951,8 @@ return [
"msg" => ["type" => "mediumtext", "comment" => ""], "msg" => ["type" => "mediumtext", "comment" => ""],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"],
"link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"iid" => ["type" => "int unsigned", "relation" => ["item" => "id"], "comment" => "item.id"], "iid" => ["type" => "int unsigned", "comment" => ""],
"parent" => ["type" => "int unsigned", "relation" => ["item" => "id"], "comment" => ""], "parent" => ["type" => "int unsigned", "comment" => ""],
"uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the related post"], "uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the related post"],
"parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the parent of the related post"], "parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the parent of the related post"],
"seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
@ -975,7 +975,7 @@ return [
"fields" => [ "fields" => [
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
"notify-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["notify" => "id"], "comment" => ""], "notify-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["notify" => "id"], "comment" => ""],
"master-parent-item" => ["type" => "int unsigned", "foreign" => ["item" => "id"], "comment" => ""], "master-parent-item" => ["type" => "int unsigned", "comment" => "Deprecated"],
"master-parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the parent of the related post"], "master-parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the parent of the related post"],
"parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""], "parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"receiver-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "receiver-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"],
@ -983,7 +983,6 @@ return [
], ],
"indexes" => [ "indexes" => [
"PRIMARY" => ["id"], "PRIMARY" => ["id"],
"master-parent-item" => ["master-parent-item"],
"master-parent-uri-id" => ["master-parent-uri-id"], "master-parent-uri-id" => ["master-parent-uri-id"],
"receiver-uid" => ["receiver-uid"], "receiver-uid" => ["receiver-uid"],
"notify-id" => ["notify-id"], "notify-id" => ["notify-id"],

View file

@ -197,7 +197,6 @@
"fields" => [ "fields" => [
"id" => ["post-user", "id"], "id" => ["post-user", "id"],
"item-id" => ["item", "id"], "item-id" => ["item", "id"],
"iid" => ["post-user", "id"],
"post-user-id" => ["post-user", "id"], "post-user-id" => ["post-user", "id"],
"uid" => ["post-thread-user", "uid"], "uid" => ["post-thread-user", "uid"],
"parent" => ["parent-post", "id"], "parent" => ["parent-post", "id"],