Fix several database issues

This commit is contained in:
Michael 2021-02-16 22:04:03 +00:00
parent 0c7c1efbd7
commit 60a6dfa23c
7 changed files with 43 additions and 30 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------
-- 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 '',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
`link` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`iid` int unsigned COMMENT 'item.id',
`iid` int unsigned COMMENT '',
`parent` int unsigned COMMENT '',
`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',
@ -915,17 +915,15 @@ CREATE TABLE IF NOT EXISTS `notify` (
CREATE TABLE IF NOT EXISTS `notify-threads` (
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
`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',
`parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
PRIMARY KEY(`id`),
INDEX `master-parent-item` (`master-parent-item`),
INDEX `master-parent-uri-id` (`master-parent-uri-id`),
INDEX `receiver-uid` (`receiver-uid`),
INDEX `notify-id` (`notify-id`),
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 (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
@ -1748,7 +1746,6 @@ DROP VIEW IF EXISTS `post-thread-view`;
CREATE VIEW `post-thread-view` AS SELECT
`post-user`.`id` AS `id`,
`item`.`id` AS `item-id`,
`post-user`.`id` AS `iid`,
`post-user`.`id` AS `post-user-id`,
`post-thread-user`.`uid` AS `uid`,
`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',
'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()]);

View file

@ -224,7 +224,7 @@ class Post
$selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
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;
// 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.
if ($is_owner || !$last_updated) {
if ($_GET['force'] && !empty($_GET['item'])) {
// When the parent is provided, we only fetch this
$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`";
} else {
$gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);

View file

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

View file

@ -55,7 +55,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1400);
define('DB_UPDATE_VERSION', 1401);
}
return [
@ -951,8 +951,8 @@ return [
"msg" => ["type" => "mediumtext", "comment" => ""],
"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" => ""],
"iid" => ["type" => "int unsigned", "relation" => ["item" => "id"], "comment" => "item.id"],
"parent" => ["type" => "int unsigned", "relation" => ["item" => "id"], "comment" => ""],
"iid" => ["type" => "int unsigned", "comment" => ""],
"parent" => ["type" => "int unsigned", "comment" => ""],
"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"],
"seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
@ -975,7 +975,7 @@ return [
"fields" => [
"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" => ""],
"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"],
"parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"receiver-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"],
@ -983,7 +983,6 @@ return [
],
"indexes" => [
"PRIMARY" => ["id"],
"master-parent-item" => ["master-parent-item"],
"master-parent-uri-id" => ["master-parent-uri-id"],
"receiver-uid" => ["receiver-uid"],
"notify-id" => ["notify-id"],

View file

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