зеркало из https://github.com/nextcloud/text.git
fix(resetSessions): Truncate tables and rename documents folder
This is way more performant than iterating over all existing sessions. Signed-off-by: Jonas <jonas@freesources.org>
This commit is contained in:
Родитель
f7601878a4
Коммит
914c10054b
|
@ -77,6 +77,12 @@ class ResetDocument extends Command {
|
|||
return 1;
|
||||
}
|
||||
|
||||
if ($all && $fullReset) {
|
||||
// Truncate tables and clear document directory
|
||||
$this->documentService->clearAll();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($all) {
|
||||
$fileIds = [];
|
||||
foreach ($this->documentService->getAll() as $document) {
|
||||
|
|
|
@ -79,4 +79,10 @@ class DocumentMapper extends QBMapper {
|
|||
$result->closeCursor();
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function clearAll(): void {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->delete($this->getTableName())
|
||||
->executeStatement();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,6 +165,12 @@ class SessionMapper extends QBMapper {
|
|||
return $qb->executeStatement();
|
||||
}
|
||||
|
||||
public function clearAll(): void {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->delete($this->getTableName())
|
||||
->executeStatement();
|
||||
}
|
||||
|
||||
public function isUserInDocument(int $documentId, string $userId): bool {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$result = $qb->select('*')
|
||||
|
|
|
@ -76,6 +76,12 @@ class StepMapper extends QBMapper {
|
|||
->executeStatement();
|
||||
}
|
||||
|
||||
public function clearAll(): void {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->delete($this->getTableName())
|
||||
->executeStatement();
|
||||
}
|
||||
|
||||
// not in use right now
|
||||
public function deleteBeforeVersion(int $documentId, int $version): int {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
|
|
@ -26,13 +26,6 @@ class ResetSessionsBeforeYjs implements IRepairStep {
|
|||
return;
|
||||
}
|
||||
|
||||
$output->startProgress($this->documentService->countAll());
|
||||
foreach ($this->documentService->getAll() as $document) {
|
||||
$fileId = $document->getId();
|
||||
$this->documentService->unlock($fileId);
|
||||
$this->documentService->resetDocument($fileId, true);
|
||||
$output->advance();
|
||||
}
|
||||
$output->finishProgress();
|
||||
$this->documentService->clearAll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ use OCP\Files\NotPermittedException;
|
|||
use OCP\Files\SimpleFS\ISimpleFile;
|
||||
use OCP\ICache;
|
||||
use OCP\ICacheFactory;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\Lock\LockedException;
|
||||
use OCP\PreConditionNotMetException;
|
||||
|
@ -87,8 +88,9 @@ class DocumentService {
|
|||
private IAppData $appData;
|
||||
private ILockManager $lockManager;
|
||||
private IUserMountCache $userMountCache;
|
||||
private IConfig $config;
|
||||
|
||||
public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, SessionMapper $sessionMapper, IAppData $appData, ?string $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, LoggerInterface $logger, ShareManager $shareManager, IRequest $request, IManager $directManager, ILockManager $lockManager, IUserMountCache $userMountCache) {
|
||||
public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, SessionMapper $sessionMapper, IAppData $appData, ?string $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, LoggerInterface $logger, ShareManager $shareManager, IRequest $request, IManager $directManager, ILockManager $lockManager, IUserMountCache $userMountCache, IConfig $config) {
|
||||
$this->documentMapper = $documentMapper;
|
||||
$this->stepMapper = $stepMapper;
|
||||
$this->sessionMapper = $sessionMapper;
|
||||
|
@ -100,6 +102,7 @@ class DocumentService {
|
|||
$this->shareManager = $shareManager;
|
||||
$this->lockManager = $lockManager;
|
||||
$this->userMountCache = $userMountCache;
|
||||
$this->config = $config;
|
||||
$token = $request->getParam('token');
|
||||
if ($this->userId === null && $token !== null) {
|
||||
try {
|
||||
|
@ -662,4 +665,24 @@ class DocumentService {
|
|||
public function countAll(): int {
|
||||
return $this->documentMapper->countAll();
|
||||
}
|
||||
|
||||
private function getFullAppFolder(): Folder {
|
||||
$appFolder = $this->rootFolder->get('appdata_' . $this->config->getSystemValueString('instanceid', '') . '/text');
|
||||
if (!$appFolder instanceof Folder) {
|
||||
throw new NotFoundException('Folder not found');
|
||||
}
|
||||
return $appFolder;
|
||||
}
|
||||
|
||||
public function clearAll(): void {
|
||||
$this->stepMapper->clearAll();
|
||||
$this->sessionMapper->clearAll();
|
||||
$this->documentMapper->clearAll();
|
||||
try {
|
||||
$appFolder = $this->getFullAppFolder();
|
||||
$appFolder->get('documents')->move($appFolder->getPath() . '/documents_old_' . time());
|
||||
} catch (NotFoundException) {
|
||||
}
|
||||
$this->ensureDocumentsFolder();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use OCP\Files\IRootFolder;
|
|||
use OCP\Files\Lock\ILockManager;
|
||||
use OCP\Files\NotPermittedException;
|
||||
use OCP\ICacheFactory;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\Share\IManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -49,6 +50,7 @@ class DocumentServiceTest extends \PHPUnit\Framework\TestCase {
|
|||
$this->directManager = $this->createMock(\OCP\DirectEditing\IManager::class);
|
||||
$this->lockManager = $this->createMock(ILockManager::class);
|
||||
$this->userMountCache = $this->createMock(IUserMountCache::class);
|
||||
$config = $this->createMock(IConfig::class);
|
||||
|
||||
$this->documentService = new DocumentService(
|
||||
$this->documentMapper,
|
||||
|
@ -64,6 +66,7 @@ class DocumentServiceTest extends \PHPUnit\Framework\TestCase {
|
|||
$this->directManager,
|
||||
$this->lockManager,
|
||||
$this->userMountCache,
|
||||
$config,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче