Skip to content
This repository has been archived by the owner on Aug 9, 2020. It is now read-only.

List directory contents non-recursively #13

Merged
merged 1 commit into from
Oct 15, 2015

Conversation

zaak
Copy link
Contributor

@zaak zaak commented Oct 14, 2015

This PR allows for non-recursive content listing. The previous approach was always fetching all objects recursively (by prefix), which is really inefficient in case if some of the subdirectories contains a large number of files.

http://docs.aws.amazon.com/AmazonS3/latest/dev/ListingKeysHierarchy.html
http://codereview.stackexchange.com/questions/6847/list-objects-in-a-amazon-s3-folder-without-also-listing-objects-in-sub-folders/6850#6850

@zaak zaak force-pushed the master branch 2 times, most recently from 36a8a8f to 1a4a633 Compare October 14, 2015 09:41
@@ -438,7 +448,7 @@ public function listContents($dirname = '', $recursive = false)
*/
protected function normalizeResponse(array $object, $path = null)
{
$result = ['path' => $path ?: $this->removePathPrefix($object['Key'])];
$result = ['path' => $path ?: $this->removePathPrefix(isset($object['Key']) ? $object['Key'] : $object['Prefix'])];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What case is this addressing? Is this the response for the top level directory? Something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If content is listed non-recursively prefixes are listed without Key attribute. The path of the directory is stored as Prefix. Directory level doesn't matter here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow... If the directory is stored as Prefix, then all the files would be named the same, which wouldn't be correct. Or is the file path returned under the Prefix key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. I've created a gist showing how the response from S3 looks like:
https://gist.github.com/zaak/6b0788dfbc1391849dbb, should be more clear.
I have a set of tests in our app that use Flysystem quite intensely, so I assume this change shouldn't break anything, as they all pass.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the best comment on a PR award goes tooooooooo ... @zaak! Seriously, thanks for this, this is exactly what I wanted to know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, @zaak, could we use this for the V3 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankdejonge I think yes, haven't checked it yet though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zaak version 1.0.3 is tagged and should be available shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankdejonge Awesome! Thanks! :)

frankdejonge added a commit that referenced this pull request Oct 15, 2015
List directory contents non-recursively
@frankdejonge frankdejonge merged commit 422d4f7 into thephpleague:master Oct 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants