]> source.dussan.org Git - nextcloud-server.git/commitdiff
dont hold a transaction during the move to trash 23185/head
authorRobin Appelman <robin@icewind.nl>
Wed, 30 Sep 2020 12:30:54 +0000 (14:30 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 5 Oct 2020 13:25:36 +0000 (15:25 +0200)
because moving to trash can take a long time, keeping a transaction active for the duration can lead to issues

Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_trashbin/lib/Trashbin.php

index 276cdf4e2d91a224ec3a3b3c70cdfa8fcd277ec8..284ef82a2404a507c185f74a48270eb9e24d5454 100644 (file)
@@ -285,8 +285,6 @@ class Trashbin {
                        $trashStorage->unlink($trashInternalPath);
                }
 
-               $connection = \OC::$server->getDatabaseConnection();
-               $connection->beginTransaction();
                $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
 
                try {
@@ -310,12 +308,16 @@ class Trashbin {
                        } else {
                                $sourceStorage->unlink($sourceInternalPath);
                        }
-                       $connection->rollBack();
+
+                       if ($sourceStorage->file_exists($sourceInternalPath)) {
+                               // undo the cache move
+                               $sourceStorage->getUpdater()->renameFromStorage($trashStorage, $trashInternalPath, $sourceInternalPath);
+                       } else {
+                               $trashStorage->getUpdater()->remove($trashInternalPath);
+                       }
                        return false;
                }
 
-               $connection->commit();
-
                if ($moveSuccessful) {
                        $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
                        $result = $query->execute([$filename, $timestamp, $location, $owner]);