Nextcloud app that allows admins to pre-generate previews. The app listens to edit events and stores this information. Once a cron job is triggered it will start preview generation. This means that you can better utilize your system by pre-generating previews when your system is normally idle and thus putting less load on your machine when the requests are actually served.
This app is primarily meant for small Nextcloud servers running on cheap hardware where on-demand generation of previews is not quick enough. The app effectively trades higher disk usage for quicker previews and this trade-off should be considered carefully. The previous reasoning of resource exhaustion caused by too many concurrent preview requests is not a concern anymore as there is a configurable limit in modern versions of Nextcloud.
The app does not replace on demand preview generation so if a preview is requested before it is pre-generated it will still be shown.
- Install directly from within your Nextcloud from the app store
- Clone this repository into your Nextcloud app folder
- Install the app
- Enable the app
- Run
./occ preview:generate-all
once after installation. - Add a (system) cron job for
./occ preview:pre-generate
- I run it every 10 minutes
- The app does not work with encryption enabled
- Listen to events that a file has been written or modified and store it in the database
- On cron run request previews for the files that have been written or modified
If a preview already exists at step 2 then requesting it is really cheap. If not it will be generated. Depending on the sizes of the files and the hardware you are running on the time this takes can vary.
Loop over all files and try to generate previews for them. If one or multiple user ids are supplied
it will just loop over the files of those users. You can also limit the generation to one or more
paths using --path="/[username]/files/[folder path]"
, e.g. --path="/alice/files/Photos"
. Note
that all given user_ids are ignored if at least one path is specified.
Do the actual pre-generation. This means only for new or modified files (since the app was enabled or the last pre-generation was done).
Use <command> -vv
to get a more verbose output if you are interested to see which files are being
processed.
The value of each option can either be a list of sizes separated by spaces or an empty string. Setting an empty string will simply skip those kinds of previews. Deleting or not setting a config will use a built-in default list of values for those previews.
- Preview sizes must be a power of 4! Other sizes are silently ignored.
- The smallest possible size is 64.
- The max size is determined by your
preview_max_x
andpreview_max_y
settings inconfig.php
.
Cropped square previews which are mostly used in the list and tile views of the files app.
Will retain the aspect ratio and try to maximize either width or height.
Will retain the aspect ratio and use the specified width. The height will be scaled according to the aspect ratio.
Will retain the aspect ratio and use the specified height. The width will be scaled according to the aspect ratio.
Preview generation can be a very long running job. Thus we need a system that does not time out.
Yes this happens when the pre-generate
command crashes. No worries the lock
will be released after 30 minutes of inactivity from the app. So go grab a cookie.
Follow these instructions
The following options are recommended if you only want to generate a minimum set of required previews. This should include all previews requested by the files, photos and activity apps.
./occ config:app:set --value="64 256" previewgenerator squareSizes
./occ config:app:set --value="256 4096" previewgenerator squareUncroppedSizes
./occ config:app:set --value="" previewgenerator widthSizes
./occ config:app:set --value="" previewgenerator heightSizes
This will only generate:
- Cropped square previews of: 64x64 and 256x256
- Aspect ratio previews with a max width or max height of: 256 and 4096
You need to increase the memory allowance of PHP, by default it is 128 MB. You do that by changing the memory_limit in the php.ini file.
If you use the docker container you need set the environment variable PHP_MEMORY_LIMIT
instead.
Add an empty file with the name .nomedia
in the folder you wish to skip. All files and subfolders of the folder containing .nomedia
will also be skipped.
WARNING: This is not supported but it has been confirmed to work by multiple users. Proceed at your own risk. Always keep backups around.
- Remove the folder
your-nextcloud-data-directory/appdata_*/preview
- Optional: change parameters
preview_max_x
andpreview_max_y
inconfig.php
(e.g., to512
), and change thepreviewgenerator
app parametersheightSizes
,squareSizes
andwidthSizes
as per the README (or better yet, to a low value each, e.g.512
,256
and512
respectively) - Run
occ files:scan-app-data
(this will reset generated previews in the database) - Run
occ preview:generate-all [user-id]
(this will run very fast if you did step 2)