Skip to content

Commit

Permalink
don't re-get fileinfo for versioned file if it's not shared
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Mar 10, 2023
1 parent e6317dd commit 771cd47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
26 changes: 13 additions & 13 deletions apps/files_versions/lib/Versions/LegacyVersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,46 +69,46 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array {
if ($storage->instanceOfStorage(SharedStorage::class)) {
$owner = $storage->getOwner('');
$user = $this->userManager->get($owner);
}

$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$nodes = $userFolder->getById($file->getId());
$file2 = array_pop($nodes);
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$nodes = $userFolder->getById($file->getId());
$file = array_pop($nodes);
}

$versions = $this->getVersionsForFileFromDB($file2, $user);
$versions = $this->getVersionsForFileFromDB($file, $user);

if (count($versions) > 0) {
return $versions;
}

// Insert the entry in the DB for the current version.
$versionEntity = new VersionEntity();
$versionEntity->setFileId($file2->getId());
$versionEntity->setTimestamp($file2->getMTime());
$versionEntity->setSize($file2->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file2->getMimetype()));
$versionEntity->setFileId($file->getId());
$versionEntity->setTimestamp($file->getMTime());
$versionEntity->setSize($file->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setMetadata([]);
$this->versionsMapper->insert($versionEntity);

// Insert entries in the DB for existing versions.
$versionsOnFS = Storage::getVersions($user->getUID(), $userFolder->getRelativePath($file2->getPath()));
$versionsOnFS = Storage::getVersions($user->getUID(), $userFolder->getRelativePath($file->getPath()));
foreach ($versionsOnFS as $version) {
$versionEntity = new VersionEntity();
$versionEntity->setFileId($file2->getId());
$versionEntity->setFileId($file->getId());
$versionEntity->setTimestamp((int)$version['version']);
$versionEntity->setSize((int)$version['size']);
$versionEntity->setMimetype($this->mimeTypeLoader->getId($version['mimetype']));
$versionEntity->setMetadata([]);
$this->versionsMapper->insert($versionEntity);
}

return $this->getVersionsForFileFromDB($file2, $user);
return $this->getVersionsForFileFromDB($file, $user);
}

/**
* @return IVersion[]
*/
private function getVersionsForFileFromDB(Node $file, IUser $user): array {
private function getVersionsForFileFromDB(FileInfo $file, IUser $user): array {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());

return array_map(
Expand Down
1 change: 0 additions & 1 deletion apps/files_versions/tests/VersioningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ public function testRestoreSameStorage() {
public function testRestoreCrossStorage() {
$storage2 = new Temporary([]);
\OC\Files\Filesystem::mount($storage2, [], self::TEST_VERSIONS_USER . '/files/sub');
\OC\Files\Filesystem::tearDown();

$this->doTestRestore();
}
Expand Down

0 comments on commit 771cd47

Please sign in to comment.