Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- **💾 Open format:** Files are saved as [Markdown](https://en.wikipedia.org/wiki/Markdown), so you can edit them from any other text app too.
- **✊ Strong foundation:** We use [🐈 tiptap](https://tiptap.scrumpy.io) which is based on [🦉 ProseMirror](https://prosemirror.net) – huge thanks to them!
]]></description>
<version>8.0.0-dev.0</version>
<version>8.0.0-dev.1</version>
<licence>agpl</licence>
<author mail="jus@bitgrid.net">Julius Härtl</author>
<namespace>Text</namespace>
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'OCA\\Text\\Migration\\Version030901Date20231114150437' => $baseDir . '/../lib/Migration/Version030901Date20231114150437.php',
'OCA\\Text\\Migration\\Version040100Date20240611165300' => $baseDir . '/../lib/Migration/Version040100Date20240611165300.php',
'OCA\\Text\\Migration\\Version070000Date20250925110024' => $baseDir . '/../lib/Migration/Version070000Date20250925110024.php',
'OCA\\Text\\Migration\\Version080000Date20260331132113' => $baseDir . '/../lib/Migration/Version080000Date20260331132113.php',
'OCA\\Text\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\Text\\Service\\ApiService' => $baseDir . '/../lib/Service/ApiService.php',
'OCA\\Text\\Service\\AttachmentService' => $baseDir . '/../lib/Service/AttachmentService.php',
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ComposerStaticInitText
'OCA\\Text\\Migration\\Version030901Date20231114150437' => __DIR__ . '/..' . '/../lib/Migration/Version030901Date20231114150437.php',
'OCA\\Text\\Migration\\Version040100Date20240611165300' => __DIR__ . '/..' . '/../lib/Migration/Version040100Date20240611165300.php',
'OCA\\Text\\Migration\\Version070000Date20250925110024' => __DIR__ . '/..' . '/../lib/Migration/Version070000Date20250925110024.php',
'OCA\\Text\\Migration\\Version080000Date20260331132113' => __DIR__ . '/..' . '/../lib/Migration/Version080000Date20260331132113.php',
'OCA\\Text\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\Text\\Service\\ApiService' => __DIR__ . '/..' . '/../lib/Service/ApiService.php',
'OCA\\Text\\Service\\AttachmentService' => __DIR__ . '/..' . '/../lib/Service/AttachmentService.php',
Expand Down
8 changes: 1 addition & 7 deletions lib/Cron/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ public function __construct(
*/
protected function run($argument): void {
$this->logger->debug('Run cleanup job for text documents');
foreach ($this->documentService->getAll() as $document) {
if ($this->sessionService->countAllSessions($document->getId()) > 0) {
// Do not reset if there are any sessions left
// Inactive sessions will get removed further down and will trigger a reset next time
continue;
}

foreach ($this->documentService->getAllWithNoActiveSession() as $document) {
try {
$this->documentService->resetDocument($document->getId());
} catch (DocumentHasUnsavedChangesException) {
Expand Down
16 changes: 16 additions & 0 deletions lib/Db/DocumentMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ public function findAll(): Generator {
}
}

public function findAllWithNoActiveSessions(): Generator {
$qb = $this->db->getQueryBuilder();
$result = $qb->select('d.*')
->from($this->getTableName(), 'd')
->leftJoin('d', 'text_sessions', 's', $qb->expr()->eq('s.document_id', 'd.id'))
->where($qb->expr()->isNull('s.id'))
->executeQuery();
try {
while ($row = $result->fetch()) {
yield $this->mapRowToEntity($row);
}
} finally {
$result->closeCursor();
}
}

public function countAll(): int {
$qb = $this->db->getQueryBuilder();
$qb->select($qb->func()->count('id'))
Expand Down
70 changes: 70 additions & 0 deletions lib/Migration/Version080000Date20260331132113.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Text\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\Attributes\AddIndex;
use OCP\Migration\Attributes\IndexType;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

#[AddIndex(table: 'text_steps', type: IndexType::INDEX, description: 'Optimize cleanup job')]
class Version080000Date20260331132113 extends SimpleMigrationStep {
private bool $addIndexLater = false;

public function __construct(
private readonly IDBConnection $connection,
) {
}

#[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('text_steps');
if (!$table->hasIndex('text_steps_doc_id_id_index')) {
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_MARIADB
|| $this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) {
$table->addIndex(['document_id', 'id'], 'text_steps_doc_id_id_index');
} else {
$this->addIndexLater = true;
}
return $schema;
}

return null;
}

#[Override]
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if ($this->addIndexLater) {
// We need to add the index with a DESC manually
// See https://github.com/doctrine/orm/issues/8128
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_POSTGRES) {
$stm = $this->connection->prepare('CREATE INDEX CONCURRENTLY text_steps_doc_id_id_index ON **PREFIX**text_steps (document_id, id DESC);');
} elseif ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
$stm = $this->connection->prepare('CREATE INDEX text_steps_doc_id_id_index ON **PREFIX**text_steps (document_id, id DESC) ONLINE;');
} elseif ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
$stm = $this->connection->prepare('CREATE INDEX text_steps_doc_id_id_index ON **PREFIX**text_steps (document_id, id DESC);');
} else {
throw new \RuntimeException('Unsupported platform');
}
$stm->execute();
return $schema;
}
return null;
}
}
4 changes: 4 additions & 0 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ public function getAll(): \Generator {
return $this->documentMapper->findAll();
}

public function getAllWithNoActiveSession(): \Generator {
return $this->documentMapper->findAllWithNoActiveSessions();
}

/**
* @throws NotPermittedException
* @throws NotFoundException
Expand Down
Loading