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

Question - Cache warmup #156

Closed
Maxwell2022 opened this issue Mar 5, 2013 · 8 comments
Closed

Question - Cache warmup #156

Maxwell2022 opened this issue Mar 5, 2013 · 8 comments
Labels
Attn: Critical This issue or PR is critical and should be rushed into a new release ASAP.

Comments

@Maxwell2022
Copy link

Hi,

This is more a question than a bug (maybe a feature request).
Images in my application are uploaded to S3 (it take a while depending of the size).
Once the upload is finished, I display a preview of the content using Liip (twig filter) to resolve the image from the cache (S3 cache too).

The preview image take at least 20 seconds to be displayed because it has to download the original, apply the filter, save the thumbnail on S3 and finally display it.

I'm wondering if it's possible to generate this thumbnail in PHP directly like that I don't have the latence in the frontend at least?

Cheers,
Maxime

@havvg
Copy link
Contributor

havvg commented Mar 5, 2013

Hi, check out #142 und #150. Tell me whether this helps you, or what's missing!
With this you are able to edit the file right away and upload the thumbnail even before the original and maybe post pone the upload of the original file to kernel.terminate.

@Maxwell2022
Copy link
Author

Thanks! That might be the solution. I'll have a look tomorrow for the thumbnail generation.
So if I understood correctly applyFilter() is saving the image directly into the configured cache?
$filterManager->applyFilter($image, 'thumbnail');

If this is woking I can upload the original later on using a queue system and doing it in the background.
This could work as long as I have the thumbnail generated ;)

@havvg
Copy link
Contributor

havvg commented Mar 5, 2013

No, applyFilter only returns the image, you can then do, whatever you want with it e.g. save it, or forward it to the CacheManager to store it with the respective Resolver. Take a look at the ImagineController how it works all together.

@Maxwell2022
Copy link
Author

ok thanks for the explanation ;)

@havvg havvg closed this as completed Mar 5, 2013
@Maxwell2022
Copy link
Author

ok I've managed to do it but it looks quite fastidious. Here is my code:

    // Generate the thumbnail
    $image = $this->imagine->open($file->getPathname());
    $image = $this->imagineFilterManager->applyFilter($image, $this->filterName);

    // Get a response object to store it in the cache
    $request = new Request();
    $response = $this->imagineFilterManager->get($request, $this->filterName, $image, $file->getPathname());

    // Store the response in the cache
    $this->imagineCacheManager->store($response, $remote, $this->filterName);

I needed to create a dummy Request object to get a Response object from FilterManager::get()
It still very slow to render the thumbnail I guess because the CacheResolver has to dialogue with S3 to know if the object exists first. I might remove the filter in the twig template, hopping that all thumbnails are generated correctly.

@Maxwell2022
Copy link
Author

Ok, I found out why it was slow... it was because it was not prefixing the targetPath with the filter name so it end up being save in a different folder.

I had to prefix it manually:

    // Store the response in the cache
    $this->imagineCacheManager->store($response, $this->filterName.'/'.$remote, $this->filterName);

@Maxwell2022
Copy link
Author

Still eating some of the page load (~1sec/image).
I have a page with 12 images displayed using the imagine_filter and it's taking around 15 seconds to load the page.

<img src="{{ content.image | imagine_filter('content_thumb') }}" />

Is there anyway to speed up the resolver for S3?

@havvg
Copy link
Contributor

havvg commented Mar 6, 2013

You can extend it with e.g. Memcached for result caching whether the object exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Attn: Critical This issue or PR is critical and should be rushed into a new release ASAP.
Projects
None yet
Development

No branches or pull requests

2 participants