diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2020-04-01 14:08:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-01 14:08:48 +0300 |
commit | 547f50fd1c564364f221c2d7424439f03d74aba8 (patch) | |
tree | 8f9619f8ece6712693cd41f83c3e3c33047e8b0d | |
parent | ae9a7b542fb92491a6947739f0651fc199b672f3 (diff) | |
parent | 98ddbcd843ca8c1cb3a130385b21db27ff82a111 (diff) |
Merge pull request #3225 from nextcloud/backport/3220/stable18
[stable18] Reduce database load against participants table
-rw-r--r-- | appinfo/info.xml | 2 | ||||
-rw-r--r-- | docs/conversation.md | 2 | ||||
-rw-r--r-- | lib/Controller/CallController.php | 5 | ||||
-rw-r--r-- | lib/Controller/RoomController.php | 2 | ||||
-rw-r--r-- | lib/Migration/Version8000Date20200331144101.php | 54 |
5 files changed, 60 insertions, 5 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml index a2b3da4a1..0e0bb6cc1 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m ]]></description> - <version>8.0.5</version> + <version>8.0.5.1</version> <licence>agpl</licence> <author>Daniel Calviño Sánchez</author> diff --git a/docs/conversation.md b/docs/conversation.md index 1d5b7bd34..08cc5a85b 100644 --- a/docs/conversation.md +++ b/docs/conversation.md @@ -25,7 +25,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1` `participantInCall` | bool | Flag if the current user is in the call (deprecated, use `participantFlags` instead) `participantFlags` | int | Flags of the current user (only available with `in-call-flags` capability) `readOnly` | int | Read-only state for the current user (only available with `read-only-rooms` capability) - `count` | int | Number of active users + `count` | int | **Deprecated:** ~~Number of active users~~ - always returns `0` now `numGuests` | int | Number of active guests `lastPing` | int | Timestamp of the last ping of the current user (should be used for sorting) `sessionId` | string | `'0'` if not connected, otherwise a 512 character long string diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php index 3f743538a..9a08f3cd1 100644 --- a/lib/Controller/CallController.php +++ b/lib/Controller/CallController.php @@ -53,10 +53,11 @@ class CallController extends AEnvironmentAwareController { * @return DataResponse */ public function getPeersForCall(): DataResponse { + $timeout = $this->timeFactory->getTime() - 30; $result = []; - $participants = $this->room->getParticipants($this->timeFactory->getTime() - 30); + $participants = $this->room->getParticipantsInCall(); foreach ($participants as $participant) { - if ($participant->getSessionId() === '0' || $participant->getInCallFlags() === Participant::FLAG_DISCONNECTED) { + if ($participant->getLastPing() < $timeout) { // User is not active in call continue; } diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 1ddfc5e42..ce86395e8 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -234,7 +234,7 @@ class RoomController extends AEnvironmentAwareController { 'participantInCall' => ($currentParticipant->getInCallFlags() & Participant::FLAG_IN_CALL) !== 0, 'participantFlags' => $currentParticipant->getInCallFlags(), 'readOnly' => $room->getReadOnly(), - 'count' => $room->getNumberOfParticipants(false, $this->timeFactory->getTime() - 30), + 'count' => 0, // Deprecated, remove in future API version 'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface, 'lastActivity' => $lastActivity, 'isFavorite' => $currentParticipant->isFavorite(), diff --git a/lib/Migration/Version8000Date20200331144101.php b/lib/Migration/Version8000Date20200331144101.php new file mode 100644 index 000000000..b98da8824 --- /dev/null +++ b/lib/Migration/Version8000Date20200331144101.php @@ -0,0 +1,54 @@ +<?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 Version8000Date20200331144101 extends SimpleMigrationStep { + + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('talk_participants'); + if (!$table->hasIndex('tp_ident')) { + $table->addUniqueIndex(['room_id', 'user_id', 'session_id'], 'tp_ident'); + } + if (!$table->hasIndex('tp_room')) { + $table->addIndex(['room_id'], 'tp_room'); + } + if (!$table->hasIndex('tp_last_ping')) { + $table->addIndex(['last_ping'], 'tp_last_ping'); + } + if (!$table->hasIndex('tp_in_call')) { + $table->addIndex(['in_call'], 'tp_in_call'); + } + + return $schema; + } +} |