mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 01:18:37 +00:00
Merge pull request #9608 from appwrite/fix-image-transformations-cache
Fix: image transformation cache
This commit is contained in:
commit
2e784c0e8b
1 changed files with 11 additions and 4 deletions
|
|
@ -390,7 +390,8 @@ App::init()
|
||||||
->inject('timelimit')
|
->inject('timelimit')
|
||||||
->inject('mode')
|
->inject('mode')
|
||||||
->inject('apiKey')
|
->inject('apiKey')
|
||||||
->action(function (App $utopia, Request $request, Response $response, Document $project, Document $user, Publisher $publisher, Event $queueForEvents, Messaging $queueForMessaging, Audit $queueForAudits, Delete $queueForDeletes, EventDatabase $queueForDatabase, Build $queueForBuilds, StatsUsage $queueForStatsUsage, Database $dbForProject, callable $timelimit, string $mode, ?Key $apiKey) use ($usageDatabaseListener, $eventDatabaseListener) {
|
->inject('plan')
|
||||||
|
->action(function (App $utopia, Request $request, Response $response, Document $project, Document $user, Publisher $publisher, Event $queueForEvents, Messaging $queueForMessaging, Audit $queueForAudits, Delete $queueForDeletes, EventDatabase $queueForDatabase, Build $queueForBuilds, StatsUsage $queueForStatsUsage, Database $dbForProject, callable $timelimit, string $mode, ?Key $apiKey, array $plan) use ($usageDatabaseListener, $eventDatabaseListener) {
|
||||||
|
|
||||||
$route = $utopia->getRoute();
|
$route = $utopia->getRoute();
|
||||||
|
|
||||||
|
|
@ -520,6 +521,10 @@ App::init()
|
||||||
|
|
||||||
$useCache = $route->getLabel('cache', false);
|
$useCache = $route->getLabel('cache', false);
|
||||||
if ($useCache) {
|
if ($useCache) {
|
||||||
|
$route = $utopia->match($request);
|
||||||
|
$isImageTransformation = $route->getPath() === '/v1/storage/buckets/:bucketId/files/:fileId/preview';
|
||||||
|
$isDisabled = isset($plan['imageTransformations']) && $plan['imageTransformations'] === -1 && !Auth::isPrivilegedUser(Authorization::getRoles());
|
||||||
|
|
||||||
$key = md5($request->getURI() . '*' . implode('*', $request->getParams()) . '*' . APP_CACHE_BUSTER);
|
$key = md5($request->getURI() . '*' . implode('*', $request->getParams()) . '*' . APP_CACHE_BUSTER);
|
||||||
$cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key));
|
$cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key));
|
||||||
$cache = new Cache(
|
$cache = new Cache(
|
||||||
|
|
@ -532,7 +537,7 @@ App::init()
|
||||||
$parts = explode('/', $cacheLog->getAttribute('resourceType'));
|
$parts = explode('/', $cacheLog->getAttribute('resourceType'));
|
||||||
$type = $parts[0] ?? null;
|
$type = $parts[0] ?? null;
|
||||||
|
|
||||||
if ($type === 'bucket') {
|
if ($type === 'bucket' && (!$isImageTransformation || !$isDisabled)) {
|
||||||
$bucketId = $parts[1] ?? null;
|
$bucketId = $parts[1] ?? null;
|
||||||
$bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId));
|
$bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId));
|
||||||
|
|
||||||
|
|
@ -573,8 +578,10 @@ App::init()
|
||||||
$response
|
$response
|
||||||
->addHeader('Cache-Control', sprintf('private, max-age=%d', $timestamp))
|
->addHeader('Cache-Control', sprintf('private, max-age=%d', $timestamp))
|
||||||
->addHeader('X-Appwrite-Cache', 'hit')
|
->addHeader('X-Appwrite-Cache', 'hit')
|
||||||
->setContentType($cacheLog->getAttribute('mimeType'))
|
->setContentType($cacheLog->getAttribute('mimeType'));
|
||||||
->send($data);
|
if (!$isImageTransformation || !$isDisabled) {
|
||||||
|
$response->send($data);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$response
|
$response
|
||||||
->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
|
->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue