Coder-Spirit / flysystem-fallback-adapter

Flysystem adapter for fallback filesystems
17 stars 5 forks source link

Increase performance by skipping has() #1

Open BartVB opened 8 years ago

BartVB commented 8 years ago

First of all; thank you for creating this adapter! It's a great help with transitioning from one storage platform to another.

I would like to make one suggestion though. Currently this is the read() method:

    public function read($path)
    {
        if ($this->mainAdapter->has($path)) {
            return $this->mainAdapter->read($path);
        }

        $result = $this->fallback->read($path);

        if (false !== $result && $this->forceCopyOnMain) {
            $this->mainAdapter->write($path, $result['contents'], new Config());
        }

        return $result;
    }

Could the first part be changed to:

        $result = $this->mainAdapter->read($path); 
        if (false !== $result) {
            return $result;
        }

This results in a 50% reduction in API calls for all reads and in the end we don't really care if the main adapter has() the requested object, all we want to know if we can read() it. Same thing goes for most other methods.

Thanks again!

castarco commented 8 years ago

Hi @BartVB , if you want you can do a pull request to this repository with the proposed change, this way the merit will be assigned to you :) . I'll try to review it in a day or two.

Thanks to you.

SamMousa commented 6 years ago

I think this one can be closed seeing as the PR for it was merged!

stephanvierkant commented 5 years ago

Please revert this change. This causes problems since file_get_contents triggers a warning when the file does not exist.

See https://github.com/1up-lab/OneupFlysystemBundle/issues/180