SociallyDev / Spaces-API

An API wrapper for DigitalOcean's Spaces object storage designed for easy use.
MIT License
218 stars 103 forks source link

[Bug]: GetSigned URL Performance Issue compared to V2 of API #84

Closed muhammedc closed 10 months ago

muhammedc commented 2 years ago

What happened?

After migrating to v3.5.0 from v2, the getsignedURL function performance has degraded significantly compared to v2, when used in a loop and getting the url for a bunch of stored files.

Prior in v2, this would take about 2-5 seconds to obtain and generate signed urls for about 30 files... now after migrating to v3.5.0, it takes about 15-20 seconds to generate the same...

Any ideas or suggestions?

Version

3.5.0

What version of PHP are you using?

7.4.1

Relevant log output

No response

MacroMan commented 1 year ago

We made changes to way file data is fetched from Spaces, and I know why it's taking you longer. I don't have a solution right now, but I will look into supporting what you need.

muhammedc commented 1 year ago

Many thanks for letting me know. Is there a temporary hack to speedup performance, or should I revert to v2 until such time a solution or fix is available?

MacroMan commented 1 year ago

Can you post the code loop you're using?

muhammedc commented 1 year ago

sure... here you go:

<?php foreach ($filesResult as $f1) {?>
    <tr>

    <td>
    </td>

    <td>
        <?php echo '<span data-toggle="tooltip" title="' . $f1['ID'] . '">' . $f1['DATE'] . '</span>'; ?>
    </td>

    <td>
        <?php echo $f1['DESCRIPTION']; ?>
    </td>

    <td>
        <?php echo $f1['TYPE']; ?>
    </td>

    <td>
        <?php echo number_format($f1['SIZE'] / 1048576, 2) . ' MB'; ?>
    </td>

    <td>
        <?php 
            $authurl = $my_Space->file($f1['FILENAME'])->getsignedURL("15 minutes")); //This code is for Spaces-API ^v3.5.0 - performance issues                                  
            echo (<a href="$authurl">$f1['FILENAME']</a>); 
        ?>
    </td>                           
<?php } ?>
MacroMan commented 1 year ago

How are you retrieving $filesResult? If you used $my_space->listFiles() then you shouldn't need to do $my_Space->file($f1['FILENAME'])->getsignedURL("15 minutes")) but just $f1->getsignedURL("15 minutes"))

MacroMan commented 1 year ago

I have just pushed an update. Upgrade to 3.6.0 and you can now pass a second arg to Space::file(string $filename, bool $validate) like so: $my_Space->file($f1['FILENAME'], false) which will disable checking if the file exists. This should speed up the call. Let me know if that has worked for you

muhammedc commented 1 year ago

How are you retrieving $filesResult? If you used $my_space->listFiles() then you shouldn't need to do $my_Space->file($f1['FILENAME'])->getsignedURL("15 minutes")) but just $f1->getsignedURL("15 minutes"))

Hi - $fileResults - Thats an internal db query to get the list.

muhammedc commented 1 year ago

I have just pushed an update. Upgrade to 3.6.0 and you can now pass a second arg to Space::file(string $filename, bool $validate) like so: $my_Space->file($f1['FILENAME'], false) which will disable checking if the file exists. This should speed up the call. Let me know if that has worked for you

Thanks - I will check and revert as soon as I am back from leave :-)

MacroMan commented 1 year ago

Have you had a chance to see if this has fixed your problem?

muhammedc commented 1 year ago

Hi, Not yet - Its scheduled for next weeks build test. Although I am gonna try to schedule some time before - Will let you know ASAP. Sorry for the delay - We are approaching build freeze and am running around trying to tick off each TO DO Item before freeze.

On Wed, Nov 16, 2022 at 1:35 PM David Wakelin @.***> wrote:

Have you had a chance to see if this has fixed your problem?

— Reply to this email directly, view it on GitHub https://github.com/SociallyDev/Spaces-API/issues/84#issuecomment-1316856478, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXMFMB22FVN66DYCP4ZKHDWITBITANCNFSM6AAAAAARYJM554 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

muhammedc commented 1 year ago

I have tested it - There is a definite improvement - but still slow compared to v2.0.1. Current benchmarks with 28 urls:

MacroMan commented 10 months ago

This library is now deprecated and this bug will not be fixed. We recommend using the official SDK or the Laravel package