Skip to content

Introducing the maximum size preview #14879

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

Merged
merged 1 commit into from
Apr 7, 2015
Merged

Introducing the maximum size preview #14879

merged 1 commit into from
Apr 7, 2015

Conversation

oparoz
Copy link
Contributor

@oparoz oparoz commented Mar 13, 2015

Replaces #13674

Fixes

The problem

You've just uploaded a 100MB TIFF file that you need to share with a restricted audience. Here is what currently happens once the file has been uploaded.

  • A 36x36 thumbnail is generated in 1 minute
  • Go to the Gallery, an album thumbnail might be generated in 1 minute
  • Go inside the album, another thumbnail will be generated in 1 minute
  • Click on the picture to get a full screen preview. 1 minute
  • Go back to the Files app and share the file
  • Client 1 visits the link. 1 minute to get the preview
  • Client 2 with a different screen resolution visits the link. 1 minute again

You're starting to get it. Every time a slightly different preview size is asked, a full conversion of that 100MB TIFF to PNG is performed. This is highly inefficient.

Proposed solution

  • Enforce maximum preview dimensions in the config. They're currently set to null.
  • The first time we're asked to generate a preview we'll generate one of the maximum dimension indicated in the configuration and all future resizing requests will be done on that preview in order to not waste time converting the same large file over and over

Default size is 2048x2048
The maximum size preview is keeping the aspect ratio of the original and is not upscaled.
It's is immediately stored in the cache with a special max tag and size identifiers based on its real size.

Every time a preview of a different size is asked, we store it in the cache. This also speeds up operation at the cost of disk space.

This make a huge difference in libraries holding several large files, for people using apps such as the Gallery.

Recreated after the loss of #13582

@karlitschek
Copy link
Contributor

@georgehrke What is your opinion?

$this->configMaxX = \OC_Config::getValue('preview_max_x', null);
$this->configMaxY = \OC_Config::getValue('preview_max_y', null);
$this->maxScaleFactor = \OC_Config::getValue('preview_max_scale_factor', 2);
$this->configMaxX = \OC::$server->getConfig()->getSystemValue('preview_max_x', 2048);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we maybe modify the constructor to expect some OCP\IConfig and if null is given fall back to \OC::$server->getConfig() (edit: and the same for logging)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems doable, but is it the right patch to modify the signature? Wouldn't it be better to introduce that in a PR which can be given as a reference to the change so that people can start modifying their code? cc @MorrisJobke @LukasReschke

Copy link
Contributor

Choose a reason for hiding this comment

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

People should never create a \OC\Preview instance directly and use getPreviewManager anyway.
(but removing all direct creations of \OC\Preview in core should definitely be done in a separate pr. (will take care))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, except that, sometimes, it's not possible to use it as PreviewManager is not yet a true replacement of \OC\Preview
See #12772 for what's missing

But if it's confirmed that the signature change should happen here, I'll do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the right approach, but will conflict greatly with #14857

Maybe you can wait, until that is done, since it is a major rework on the same file aswell ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable. I'll let you adjust the signature then and will update this PR when you're done.

@georgehrke
Copy link
Contributor

Code looks good to me otherwise

  • Add unit tests for newly introduced methods

@@ -921,7 +1056,7 @@ public static function post_delete($args, $prefix='') {
* @return bool
*/
public static function isAvailable(\OC\Files\FileInfo $file) {
if (!\OC_Config::getValue('enable_previews', true)) {
if (!\OC::$server->getConfig()->getSystemValue('enable_previews', true)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will conflict with #14857

@oparoz
Copy link
Contributor Author

oparoz commented Mar 19, 2015

Since there were no newly introduced public methods, I just did an extensive preview size test.

I'm also forcing a resize since the image provider is not doing it's resizing job properly and since that's what people are going to use the most.

I've found that testing the file individually (using the bootstrap) will WIPE your admin's data.

Note: It's possible to tweak the preview size and get the test to fail, because of this bug: #14712

@oparoz
Copy link
Contributor Author

oparoz commented Apr 7, 2015

@georgehrke @MorrisJobke @PVince81 @DeepDiver1975
Could me merge this before the PR goes, once again, out of sync?

@oparoz
Copy link
Contributor Author

oparoz commented Apr 7, 2015

Maybe @icewind1991 and @jancborchardt want to test it as well since this benefits the Gallery apps.

$file, $this->configMaxX, $this->configMaxY, $scalingUp = false, $this->fileView
);

if (!($preview instanceof \OC_Image)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the interface please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, thanks.

The first time we're asked to generate a preview we'll generate one of the maximum dimension indicated in the configuration and all future resizing requests will be done on that preview in order to not waste time converting the same file over and over.

One of the fixes required for #12465
@scrutinizer-notifier
Copy link

The inspection completed: 2 new issues, 6 updated code elements

@ghost
Copy link

ghost commented Apr 7, 2015

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/11279/
🚀 Test PASSed.🚀
chuck

@MorrisJobke
Copy link
Contributor

Tested and works 👍

@georgehrke
Copy link
Contributor

mentioned issues fixed, works 👍

MorrisJobke added a commit that referenced this pull request Apr 7, 2015
Introducing the maximum size preview
@MorrisJobke MorrisJobke merged commit 6c327f8 into owncloud:master Apr 7, 2015
@oparoz oparoz deleted the fix-preview-caching branch April 23, 2015 22:17
@lock lock bot locked as resolved and limited conversation to collaborators Aug 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants