Skip to content
Prev Previous commit
Next Next commit
feat(logging): Add some logging to document cleanup
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and backportbot-nextcloud[bot] committed Mar 9, 2023
commit a5b9229ceab538dacf58b47bc6f153c91231d57d
16 changes: 14 additions & 2 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,17 @@ public function create($fileId = null, $filePath = null, $token = null, $guestNa
if ($forceRecreate || count($remainingSessions) === 0) {
$freshSession = true;
try {
$this->logger->info('Attempt to reset document during session create for ' . $file->getId());
$this->documentService->resetDocument($file->getId(), $forceRecreate);
} catch (DocumentHasUnsavedChangesException $e) {
$this->logger->debug('Failed to reset document during session create for ' . $file->getId(), [
'remainingSessions' => $remainingSessions,
]);
}
} else {
$this->logger->info('Keep previous document state of ' . $file->getId(), [
'remainingSessions' => $remainingSessions,
]);
}

$document = $this->documentService->createDocument($file);
Expand All @@ -132,20 +140,22 @@ public function create($fileId = null, $filePath = null, $token = null, $guestNa
$session = $this->sessionService->initSession($document->getId(), $guestName);

if ($freshSession) {
$this->logger->debug('Starting a fresh session');
$this->logger->debug('Starting a fresh editing session for ' . $file->getId());
$documentState = null;
$content = $this->loadContent($file);
} else {
$this->logger->debug('Loading existing session');
$this->logger->debug('Loading existing session for ' . $file->getId());
$content = null;
try {
$stateFile = $this->documentService->getStateFile($document->getId());
$documentState = $stateFile->getContent();
} catch (NotFoundException $e) {
$this->logger->debug('State file not found for ' . $file->getId());
$documentState = ''; // no state saved yet.
// If there are no steps yet we might still need the content.
$steps = $this->documentService->getSteps($document->getId(), 0);
if (empty($steps)) {
$this->logger->debug('Empty steps, loading content for ' . $file->getId());
$content = $this->loadContent($file);
}
}
Expand Down Expand Up @@ -179,7 +189,9 @@ public function close($documentId, $sessionId, $sessionToken): DataResponse {
try {
$this->documentService->resetDocument($documentId);
$this->attachmentService->cleanupAttachments($documentId);
$this->logger->info('Reset unsaved changes of ' . $documentId);
} catch (DocumentHasUnsavedChangesException $e) {
$this->logger->error('Did not reset unsaved changes during close of ' . $documentId, ['exception' => $e]);
}
}
return new DataResponse([]);
Expand Down
3 changes: 2 additions & 1 deletion lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function createDocument(File $file): Document {
// This way the user can still resolve conflicts in the editor view
$stepsVersion = $this->stepMapper->getLatestVersion($document->getId());
if ($stepsVersion && ($document->getLastSavedVersion() !== $stepsVersion)) {
$this->logger->debug('Unsaved steps but collission with file, continue collaborative editing');
$this->logger->debug('Unsaved steps, continue collaborative editing');
return $document;
}
return $document;
Expand Down Expand Up @@ -258,6 +258,7 @@ private function insertSteps($documentId, $sessionId, $steps, $version): int {
}
$stepsVersion = $this->stepMapper->getLatestVersion($document->getId());
$newVersion = $stepsVersion + count($steps);
$this->logger->debug("Adding steps to $documentId: bumping version from $stepsVersion to $newVersion");
$this->cache->set('document-version-' . $document->getId(), $newVersion);
$step = new Step();
$step->setData($stepsJson);
Expand Down