From 98435359d05fcb156aa76c38e90c32e1df28843d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 11 Feb 2020 17:40:06 +0100 Subject: [PATCH] add wrapper to close connection while uploading/downloading from object store Signed-off-by: Robin Appelman --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + .../Files/ObjectStore/DBReOpenWrapper.php | 74 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 lib/private/Files/ObjectStore/DBReOpenWrapper.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 88058b0c88..ece905f2fd 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -966,6 +966,7 @@ return array( 'OC\\Files\\Notify\\Change' => $baseDir . '/lib/private/Files/Notify/Change.php', 'OC\\Files\\Notify\\RenameChange' => $baseDir . '/lib/private/Files/Notify/RenameChange.php', 'OC\\Files\\ObjectStore\\Azure' => $baseDir . '/lib/private/Files/ObjectStore/Azure.php', + 'OC\\Files\\ObjectStore\\DBReOpenWrapper' => $baseDir . '/lib/private/Files/ObjectStore/DBReOpenWrapper.php', 'OC\\Files\\ObjectStore\\HomeObjectStoreStorage' => $baseDir . '/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php', 'OC\\Files\\ObjectStore\\Mapper' => $baseDir . '/lib/private/Files/ObjectStore/Mapper.php', 'OC\\Files\\ObjectStore\\NoopScanner' => $baseDir . '/lib/private/Files/ObjectStore/NoopScanner.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index a69fbcd06d..031cda9a33 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -995,6 +995,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Files\\Notify\\Change' => __DIR__ . '/../../..' . '/lib/private/Files/Notify/Change.php', 'OC\\Files\\Notify\\RenameChange' => __DIR__ . '/../../..' . '/lib/private/Files/Notify/RenameChange.php', 'OC\\Files\\ObjectStore\\Azure' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/Azure.php', + 'OC\\Files\\ObjectStore\\DBReOpenWrapper' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/DBReOpenWrapper.php', 'OC\\Files\\ObjectStore\\HomeObjectStoreStorage' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php', 'OC\\Files\\ObjectStore\\Mapper' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/Mapper.php', 'OC\\Files\\ObjectStore\\NoopScanner' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/NoopScanner.php', diff --git a/lib/private/Files/ObjectStore/DBReOpenWrapper.php b/lib/private/Files/ObjectStore/DBReOpenWrapper.php new file mode 100644 index 0000000000..dc976f7050 --- /dev/null +++ b/lib/private/Files/ObjectStore/DBReOpenWrapper.php @@ -0,0 +1,74 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OC\Files\ObjectStore; + +use OCP\Files\ObjectStore\IObjectStore; +use OCP\IDBConnection; + +/** + * Close an reopen the database connection when reading and writing from the object store + * + * this prevents php keeping the database connection open and idle for a long time + */ +class DBReOpenWrapper implements IObjectStore { + /** @var string */ + private $innerClass; + /** @var IObjectStore */ + private $inner; + /** @var IDBConnection */ + private $database; + + public function __construct(array $parameters) { + $class = $parameters['class']; + $this->innerClass = $class; + $this->inner = new $class($parameters); + $this->database = \OC::$server->getDatabaseConnection(); + } + + public function getStorageId() { + return $this->inner->getStorageId(); + } + + public function readObject($urn) { + $this->database->close(); + $result = $this->inner->readObject($urn); + $this->database->connect(); + return $result; + } + + public function writeObject($urn, $stream) { + $this->database->close(); + $result = $this->inner->writeObject($urn, $stream); + $this->database->connect(); + return $result; + } + + public function deleteObject($urn) { + $this->inner->deleteObject($urn); + } + + public function objectExists($urn) { + return $this->inner->objectExists($urn); + } + + +}