mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-17 21:12:20 +01:00
perf(shares): Only load room tokens that actually have shares
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
68262618f4
commit
bfbcd2b429
6 changed files with 109 additions and 4 deletions
|
|
@ -18,7 +18,7 @@
|
|||
* 🌉 **Sync with other chat solutions** With [Matterbridge](https://github.com/42wim/matterbridge/) being integrated in Talk, you can easily sync a lot of other chat solutions to Nextcloud Talk and vice-versa.
|
||||
]]></description>
|
||||
|
||||
<version>22.0.0-beta.1.1</version>
|
||||
<version>22.0.0-beta.1.2</version>
|
||||
<licence>agpl</licence>
|
||||
|
||||
<author>Anna Larch</author>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use OCA\Talk\Events\RoomCreatedEvent;
|
|||
use OCA\Talk\Exceptions\ParticipantNotFoundException;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
use OCA\Talk\Federation\Authenticator;
|
||||
use OCA\Talk\Model\Attachment;
|
||||
use OCA\Talk\Model\Attendee;
|
||||
use OCA\Talk\Model\AttendeeMapper;
|
||||
use OCA\Talk\Model\SelectHelper;
|
||||
|
|
@ -479,13 +480,14 @@ class Manager {
|
|||
* @param string $userId
|
||||
* @return string[]
|
||||
*/
|
||||
public function getRoomTokensForUser(string $userId): array {
|
||||
public function getRoomTokensWithAttachmentsForUser(string $userId): array {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('r.token')
|
||||
->from('talk_attendees', 'a')
|
||||
->leftJoin('a', 'talk_rooms', 'r', $query->expr()->eq('a.room_id', 'r.id'))
|
||||
->where($query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)));
|
||||
->andWhere($query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)))
|
||||
->andWhere($query->expr()->eq('r.has_attachments', $query->createNamedParameter(Attachment::ATTACHMENTS_ATLEAST_ONE)));
|
||||
|
||||
$result = $query->executeQuery();
|
||||
$roomTokens = [];
|
||||
|
|
|
|||
87
lib/Migration/Version22000Date20250803160923.php
Normal file
87
lib/Migration/Version22000Date20250803160923.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Migration;
|
||||
|
||||
use Closure;
|
||||
use OCP\DB\ISchemaWrapper;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\DB\Types;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
use OCP\Share\IShare;
|
||||
use Override;
|
||||
|
||||
/**
|
||||
* Add column on rooms if they have at least one attachment
|
||||
*/
|
||||
class Version22000Date20250803160923 extends SimpleMigrationStep {
|
||||
public function __construct(
|
||||
protected IDBConnection $db,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IOutput $output
|
||||
* @param Closure(): ISchemaWrapper $schemaClosure
|
||||
* @param array $options
|
||||
* @return null|ISchemaWrapper
|
||||
*/
|
||||
#[Override]
|
||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
$table = $schema->getTable('talk_rooms');
|
||||
if (!$table->hasColumn('has_attachments')) {
|
||||
$table->addColumn('has_attachments', Types::SMALLINT, [
|
||||
'notnull' => false,
|
||||
'default' => 0,
|
||||
]);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IOutput $output
|
||||
* @param Closure(): ISchemaWrapper $schemaClosure
|
||||
* @param array $options
|
||||
*/
|
||||
#[Override]
|
||||
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('share_with')
|
||||
->from('share')
|
||||
->where($query->expr()->eq('share_type', $query->createNamedParameter(IShare::TYPE_ROOM)))
|
||||
->groupBy('share_with');
|
||||
|
||||
$tokens = [];
|
||||
$result = $query->executeQuery();
|
||||
while ($row = $result->fetch()) {
|
||||
$tokens[] = $row['share_with'];
|
||||
}
|
||||
$result->closeCursor();
|
||||
|
||||
// Update current conversations with the correct flag
|
||||
$chunks = array_chunk($tokens, 1000);
|
||||
$update = $this->db->getQueryBuilder();
|
||||
$update->update('talk_rooms')
|
||||
/** Can not use @see \OCA\Talk\Model\Attachment::ATTACHMENTS_ATLEAST_ONE during update */
|
||||
->set('has_attachments', $update->createNamedParameter(1))
|
||||
->where($update->expr()->in('token', $update->createParameter('tokens')));
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
$update->setParameter('tokens', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
|
||||
$update->executeStatement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -36,6 +36,9 @@ class Attachment extends Entity {
|
|||
public const TYPE_RECORDING = 'recording';
|
||||
public const TYPE_VOICE = 'voice';
|
||||
|
||||
public const ATTACHMENTS_NONE = 0;
|
||||
public const ATTACHMENTS_ATLEAST_ONE = 1;
|
||||
|
||||
/** @var int */
|
||||
protected $roomId;
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ use OCA\Talk\Exceptions\RoomProperty\RecordingConsentException;
|
|||
use OCA\Talk\Exceptions\RoomProperty\SipConfigurationException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\TypeException;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\Model\Attachment;
|
||||
use OCA\Talk\Model\Attendee;
|
||||
use OCA\Talk\Model\BreakoutRoom;
|
||||
use OCA\Talk\Participant;
|
||||
|
|
@ -1236,6 +1237,14 @@ class RoomService {
|
|||
$room->setFederatedParticipants($hasFederation);
|
||||
}
|
||||
|
||||
public function setHasAttachments(Room $room): void {
|
||||
$update = $this->db->getQueryBuilder();
|
||||
$update->update('talk_rooms')
|
||||
->set('has_attachments', $update->createNamedParameter(Attachment::ATTACHMENTS_ATLEAST_ONE, IQueryBuilder::PARAM_INT))
|
||||
->where($update->expr()->eq('id', $update->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)));
|
||||
$update->executeStatement();
|
||||
}
|
||||
|
||||
public function setLastActivity(Room $room, \DateTime $now): void {
|
||||
$update = $this->db->getQueryBuilder();
|
||||
$update->update('talk_rooms')
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use OCA\Talk\Manager;
|
|||
use OCA\Talk\Model\Attendee;
|
||||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCA\Talk\Service\RoomService;
|
||||
use OCP\AppFramework\Db\TTransactional;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Cache\CappedMemoryCache;
|
||||
|
|
@ -60,6 +61,7 @@ class RoomShareProvider implements IShareProvider {
|
|||
private IEventDispatcher $dispatcher,
|
||||
private Manager $manager,
|
||||
private ParticipantService $participantService,
|
||||
protected RoomService $roomService,
|
||||
protected ITimeFactory $timeFactory,
|
||||
private IL10N $l,
|
||||
private IMimeTypeLoader $mimeTypeLoader,
|
||||
|
|
@ -152,6 +154,8 @@ class RoomShareProvider implements IShareProvider {
|
|||
return $this->getRawShare($shareId);
|
||||
}, $this->dbConnection);
|
||||
|
||||
$this->roomService->setHasAttachments($room);
|
||||
|
||||
return $this->createShareObject($data);
|
||||
}
|
||||
|
||||
|
|
@ -787,7 +791,7 @@ class RoomShareProvider implements IShareProvider {
|
|||
*/
|
||||
#[\Override]
|
||||
public function getSharedWith($userId, $shareType, $node, $limit, $offset): array {
|
||||
$allRooms = $this->manager->getRoomTokensForUser($userId);
|
||||
$allRooms = $this->manager->getRoomTokensWithAttachmentsForUser($userId);
|
||||
|
||||
/** @var IShare[] $shares */
|
||||
$shares = [];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue