Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce requests needed for delete() #11

Merged
merged 1 commit into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/SwiftAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function rename($path, $newpath)
*/
public function delete($path)
{
$object = $this->getObject($path);
$object = $this->getObjectInstance($path);

try {
$object->delete();
Expand Down Expand Up @@ -253,17 +253,31 @@ public function getTimestamp($path)
}

/**
* Get an object.
* Get an object instance.
*
* @param string $path
*
* @return StorageObject
*/
protected function getObject($path)
protected function getObjectInstance($path)
{
$location = $this->applyPathPrefix($path);

$object = $this->container->getObject($location);

return $object;
}

/**
* Get an object instance and retrieve its metadata from storage.
*
* @param string $path
*
* @return StorageObject
*/
protected function getObject($path)
{
$object = $this->getObjectInstance($path);
$object->retrieve();

return $object;
Expand Down
3 changes: 2 additions & 1 deletion tests/SwiftAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use GuzzleHttp\Psr7\Stream;
use League\Flysystem\Config;
use org\bovigo\vfs\vfsStream;
use OpenStack\Common\Error\BadResponseError;
use org\bovigo\vfs\content\LargeFileContent;
use Nimbusoft\Flysystem\OpenStack\SwiftAdapter;

Expand Down Expand Up @@ -121,7 +122,7 @@ public function testRename()

public function testDelete()
{
$this->object->shouldReceive('retrieve')->once();
$this->object->shouldNotReceive('retrieve');
$this->object->shouldReceive('delete')->once();

$this->container->shouldReceive('getObject')
Expand Down