Merge pull request #4735 from nextcloud/techdebt/noid/cluster-compatibility

Create a new table for internal signaling and guest names with a PK
This commit is contained in:
Vincent Petry 2020-12-11 08:37:28 +01:00 коммит произвёл GitHub
Родитель e4f8ea911c b814a507d7
Коммит be0ed4a7f5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 267 добавлений и 53 удалений

Просмотреть файл

@ -99,7 +99,7 @@ class GuestManager {
if ($oldName !== $displayName) {
$query = $this->connection->getQueryBuilder();
$query->update('talk_guests')
$query->update('talk_guestnames')
->set('display_name', $query->createNamedParameter($displayName))
->where($query->expr()->eq('session_hash', $query->createNamedParameter($sessionHash)));
$query->execute();
@ -107,7 +107,7 @@ class GuestManager {
$dispatchEvent = false;
}
} catch (ParticipantNotFoundException $e) {
$this->connection->insertIfNotExist('*PREFIX*talk_guests', [
$this->connection->insertIfNotExist('*PREFIX*talk_guestnames', [
'session_hash' => $sessionHash,
'display_name' => $displayName,
], ['session_hash']);
@ -128,7 +128,7 @@ class GuestManager {
public function getNameBySessionHash(string $sessionHash, bool $allowEmpty = false): string {
$query = $this->connection->getQueryBuilder();
$query->select('display_name')
->from('talk_guests')
->from('talk_guestnames')
->where($query->expr()->eq('session_hash', $query->createNamedParameter($sessionHash)));
$result = $query->execute();
@ -153,7 +153,7 @@ class GuestManager {
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from('talk_guests')
->from('talk_guestnames')
->where($query->expr()->in('session_hash', $query->createNamedParameter($sessionHashes, IQueryBuilder::PARAM_STR_ARRAY)));
$result = $query->execute();

Просмотреть файл

@ -0,0 +1,144 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020, Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Talk\Migration;
use Closure;
use Doctrine\DBAL\Types\Types;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version11000Date20201209142525 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$changedSchema = false;
if (!$schema->hasTable('talk_internalsignaling')) {
$table = $schema->createTable('talk_internalsignaling');
// Auto increment id
$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('sender', Types::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('recipient', Types::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('message', Types::TEXT, [
'notnull' => true,
]);
$table->addColumn('timestamp', Types::INTEGER, [
'notnull' => true,
'length' => 11,
]);
$table->setPrimaryKey(['id']);
$table->addIndex(['recipient', 'timestamp'], 'tis_recipient_time');
$changedSchema = true;
}
if (!$schema->hasTable('talk_guestnames')) {
$table = $schema->createTable('talk_guestnames');
// Auto increment id
$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('session_hash', Types::STRING, [
'notnull' => false,
'length' => 64,
]);
$table->addColumn('display_name', Types::STRING, [
'notnull' => false,
'length' => 64,
'default' => '',
]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['session_hash'], 'tg_session_hash');
$changedSchema = true;
}
return $changedSchema ? $schema : null;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
if (!$this->connection->tableExists('talk_guests')) {
return;
}
$insert = $this->connection->getQueryBuilder();
$insert->insert('talk_guestnames')
->values([
'session_hash' => $insert->createParameter('session_hash'),
'display_name' => $insert->createParameter('display_name'),
]);
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from('talk_guests');
$result = $query->execute();
while ($row = $result->fetch()) {
$insert
->setParameter('session_hash', (string) $row['session_hash'])
->setParameter('display_name', (string) $row['display_name'])
;
$insert->execute();
}
$result->closeCursor();
}
}

Просмотреть файл

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020, Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Talk\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version11000Date20201209142526 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$changedSchema = false;
if ($schema->hasTable('talk_signaling')) {
$schema->dropTable('talk_signaling');
$changedSchema = true;
}
if ($schema->hasTable('talk_guests')) {
$schema->dropTable('talk_guests');
$changedSchema = true;
}
return $changedSchema ? $schema : null;
}
}

Просмотреть файл

@ -60,27 +60,32 @@ class Version2001Date20171026134605 extends SimpleMigrationStep {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('talk_signaling')) {
$table = $schema->createTable('talk_signaling');
$table->addColumn('sender', Type::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('recipient', Type::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('message', Type::TEXT, [
'notnull' => true,
]);
$table->addColumn('timestamp', Type::INTEGER, [
'notnull' => true,
'length' => 11,
]);
$table->addIndex(['recipient', 'timestamp'], 'ts_recipient_time');
}
/**
* Table had to be rebuild because it was missing a primary key
* @see Version11000Date20201209142525
*
* if (!$schema->hasTable('talk_signaling')) {
* $table = $schema->createTable('talk_signaling');
*
* $table->addColumn('sender', Type::STRING, [
* 'notnull' => true,
* 'length' => 255,
* ]);
* $table->addColumn('recipient', Type::STRING, [
* 'notnull' => true,
* 'length' => 255,
* ]);
* $table->addColumn('message', Type::TEXT, [
* 'notnull' => true,
* ]);
* $table->addColumn('timestamp', Type::INTEGER, [
* 'notnull' => true,
* 'length' => 11,
* ]);
*
* $table->addIndex(['recipient', 'timestamp'], 'ts_recipient_time');
* }
*/
if (!$schema->hasTable('talk_rooms')) {
$table = $schema->createTable('talk_rooms');

Просмотреть файл

@ -24,7 +24,6 @@ declare(strict_types=1);
*/
namespace OCA\Talk\Migration;
use Doctrine\DBAL\Types\Type;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
@ -39,25 +38,30 @@ class Version3002Date20180319104030 extends SimpleMigrationStep {
* @since 13.0.0
*/
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('talk_guests')) {
$table = $schema->createTable('talk_guests');
$table->addColumn('session_hash', Type::STRING, [
'notnull' => false,
'length' => 64,
]);
$table->addColumn('display_name', Type::STRING, [
'notnull' => false,
'length' => 64,
'default' => '',
]);
$table->addUniqueIndex(['session_hash'], 'tg_session_hash');
}
return $schema;
/**
* The table had to be redone so it contains a primary key
* @see Version11000Date20201209142525
*
* $schema = $schemaClosure();
*
* if (!$schema->hasTable('talk_guests')) {
* $table = $schema->createTable('talk_guests');
*
* $table->addColumn('session_hash', Type::STRING, [
* 'notnull' => false,
* 'length' => 64,
* ]);
* $table->addColumn('display_name', Type::STRING, [
* 'notnull' => false,
* 'length' => 64,
* 'default' => '',
* ]);
*
* $table->addUniqueIndex(['session_hash'], 'tg_session_hash');
* }
*
* return $schema;
*/
return null;
}
}

Просмотреть файл

@ -54,7 +54,7 @@ class Messages {
*/
public function deleteMessages(array $sessionIds): void {
$query = $this->db->getQueryBuilder();
$query->delete('talk_signaling')
$query->delete('talk_internalsignaling')
->where($query->expr()->in('recipient', $query->createNamedParameter($sessionIds, IQueryBuilder::PARAM_STR_ARRAY)))
->orWhere($query->expr()->in('sender', $query->createNamedParameter($sessionIds, IQueryBuilder::PARAM_STR_ARRAY)));
$query->execute();
@ -67,7 +67,7 @@ class Messages {
*/
public function addMessage(string $senderSessionId, string $recipientSessionId, string $message): void {
$query = $this->db->getQueryBuilder();
$query->insert('talk_signaling')
$query->insert('talk_internalsignaling')
->values(
[
'sender' => $query->createNamedParameter($senderSessionId),
@ -85,7 +85,7 @@ class Messages {
*/
public function addMessageForAllParticipants(Room $room, string $message): void {
$query = $this->db->getQueryBuilder();
$query->insert('talk_signaling')
$query->insert('talk_internalsignaling')
->values(
[
'sender' => $query->createParameter('sender'),
@ -123,7 +123,7 @@ class Messages {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('talk_signaling')
->from('talk_internalsignaling')
->where($query->expr()->eq('recipient', $query->createNamedParameter($sessionId)))
->andWhere($query->expr()->lte('timestamp', $query->createNamedParameter($time)));
$result = $query->execute();
@ -134,7 +134,7 @@ class Messages {
$result->closeCursor();
$query = $this->db->getQueryBuilder();
$query->delete('talk_signaling')
$query->delete('talk_internalsignaling')
->where($query->expr()->eq('recipient', $query->createNamedParameter($sessionId)))
->andWhere($query->expr()->lte('timestamp', $query->createNamedParameter($time)));
$query->execute();
@ -151,7 +151,7 @@ class Messages {
$time = $this->timeFactory->getTime() - $olderThan;
$query = $this->db->getQueryBuilder();
$query->delete('talk_signaling')
$query->delete('talk_internalsignaling')
->where($query->expr()->lt('timestamp', $query->createNamedParameter($time)));
$query->execute();
}

Просмотреть файл

@ -50,7 +50,7 @@ class ApiController extends OCSController {
*/
public function resetSpreed(): DataResponse {
$query = $this->db->getQueryBuilder();
$query->delete('talk_signaling')->execute();
$query->delete('talk_internalsignaling')->execute();
$query = $this->db->getQueryBuilder();
$query->delete('talk_rooms')->execute();
@ -58,6 +58,9 @@ class ApiController extends OCSController {
$query = $this->db->getQueryBuilder();
$query->delete('talk_attendees')->execute();
$query = $this->db->getQueryBuilder();
$query->delete('talk_guestnames')->execute();
$query = $this->db->getQueryBuilder();
$query->delete('talk_sessions')->execute();