Skip to content

Improve thumbnail reading performance with more direct access #31054

@CarlSchwan

Description

@CarlSchwan

Current state

When loading a thumbnail, we do:

  • Authentication DB requests
  • File system setup DB requests
  • Check if the user can read the file
  • Load the thumbnail from the appdata or generate the thumbnail and store it in the appdata
  • Serve the thumbnail

Idea how to fix it

The general idea is that we communicate a secret token with the clients when they fetch the list of files in a folder. This secret token is unique for each file and only valid for 5 min. When requesting a thumbnail, we need to pass this token to the request and then with it we can skip the authorization and authentication, as it was already done during the file listing.

Technical explanation

Add a new dav property that contains for each image a thumbnail_access_token. The thumbnail_access_token is generated with the following expression: hash(fileId + rounded_time + server_secret) where rounded_time is the intval(current_timestamp / 60 / 5) so that validity of the token is only 5 minutes and secret_server is secret from the config.php (an unique identifier for each instance). For S3, we can use directly pre-signed urls.

When requesting a thumbnail, the clients and the webui would need to provide the thumbnail_access_token that they previously got from the dav request. If the token is valid, we can skip the authentification and the full file system setup call and only do the appdata setup. If it's not valid or for legacy reasons are not set, we do the authentification and the file system setup.

For the web UI, the HTTP header can be set using a web worker. For the mobile and desktop client, it shouldn't be an issue to add an additional header to the requests (I hope)

Advantages

  • Performance: A lot less of DB requests are needed. Optimally none are actually needed as the fileid is already provided by the requests and this allows to find the path in the local storage and s3 storage. But I guess it will be a bit complicated to fight against the framework to not fetch that app config
  • Backward compatibility: it's not a new API, just an optional new parameter. It also means we can add support progressively to the apps and clients
  • Caching friendly: since the token is not part of the URL, the cache won't get invalidated for every request
  • Security: The token is only valid for 5 minutes and after that, a user will need the new token to fetch the thumbnail or be authorized by the server. Apps like access_control will send an invalid token, if the user doesn't have access to the dav requests. The only way for unauthorized users to access the thumbnail would be to get the secret token from the server or that an authorized user share the thumbnail_access_token quickly enough (5 min lifetime) but in that case it's easier to just share the file directly.

Disavantages

  • This will need some adaptions in every client and app that use thumbnails. Even if it can be done progressively
  • ???

Metadata

Metadata

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions