diff --git a/appinfo/info.xml b/appinfo/info.xml index 4cdaa0b5bbe..cfacbd557b7 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -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! ]]> - 8.0.0-dev.0 + 8.0.0-dev.1 agpl Julius Hรคrtl Text diff --git a/composer/composer/autoload_classmap.php b/composer/composer/autoload_classmap.php index daa77de7338..c9472f86637 100644 --- a/composer/composer/autoload_classmap.php +++ b/composer/composer/autoload_classmap.php @@ -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', diff --git a/composer/composer/autoload_static.php b/composer/composer/autoload_static.php index ef2fa93317e..3f38384e9e5 100644 --- a/composer/composer/autoload_static.php +++ b/composer/composer/autoload_static.php @@ -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', diff --git a/lib/Cron/Cleanup.php b/lib/Cron/Cleanup.php index eb749c6da30..111012362fe 100644 --- a/lib/Cron/Cleanup.php +++ b/lib/Cron/Cleanup.php @@ -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) { diff --git a/lib/Db/DocumentMapper.php b/lib/Db/DocumentMapper.php index 5b242bef9bf..efde04e80dd 100644 --- a/lib/Db/DocumentMapper.php +++ b/lib/Db/DocumentMapper.php @@ -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')) diff --git a/lib/Migration/Version080000Date20260331132113.php b/lib/Migration/Version080000Date20260331132113.php new file mode 100644 index 00000000000..fcd5d01a184 --- /dev/null +++ b/lib/Migration/Version080000Date20260331132113.php @@ -0,0 +1,70 @@ +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; + } +} diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 7fb51e67333..d3c26ab7524 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -463,6 +463,10 @@ public function getAll(): \Generator { return $this->documentMapper->findAll(); } + public function getAllWithNoActiveSession(): \Generator { + return $this->documentMapper->findAllWithNoActiveSessions(); + } + /** * @throws NotPermittedException * @throws NotFoundException