mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
update file preview cache save flow
This commit is contained in:
parent
16fe23244b
commit
cffbc77d05
1 changed files with 10 additions and 13 deletions
|
|
@ -461,6 +461,7 @@ App::init()
|
||||||
->on(Database::EVENT_DOCUMENT_DELETE, 'calculate-usage', fn ($event, $document) => $databaseListener($event, $document, $project, $queueForUsage, $dbForProject));
|
->on(Database::EVENT_DOCUMENT_DELETE, 'calculate-usage', fn ($event, $document) => $databaseListener($event, $document, $project, $queueForUsage, $dbForProject));
|
||||||
|
|
||||||
$useCache = $route->getLabel('cache', false);
|
$useCache = $route->getLabel('cache', false);
|
||||||
|
|
||||||
if ($useCache) {
|
if ($useCache) {
|
||||||
$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));
|
||||||
|
|
@ -711,13 +712,11 @@ App::shutdown()
|
||||||
* Cache label
|
* Cache label
|
||||||
*/
|
*/
|
||||||
$useCache = $route->getLabel('cache', false);
|
$useCache = $route->getLabel('cache', false);
|
||||||
var_dump('$useCache=');
|
|
||||||
var_dump($useCache);
|
|
||||||
if ($useCache) {
|
if ($useCache) {
|
||||||
$resource = $resourceType = null;
|
$resource = $resourceType = null;
|
||||||
$data = $response->getPayload();
|
$data = $response->getPayload();
|
||||||
var_dump('!empty($data[payload]=');
|
|
||||||
var_dump(!empty($data['payload']));
|
|
||||||
if (!empty($data['payload'])) {
|
if (!empty($data['payload'])) {
|
||||||
$pattern = $route->getLabel('cache.resource', null);
|
$pattern = $route->getLabel('cache.resource', null);
|
||||||
if (!empty($pattern)) {
|
if (!empty($pattern)) {
|
||||||
|
|
@ -734,10 +733,8 @@ App::shutdown()
|
||||||
$cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key));
|
$cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key));
|
||||||
$accessedAt = $cacheLog->getAttribute('accessedAt', '');
|
$accessedAt = $cacheLog->getAttribute('accessedAt', '');
|
||||||
$now = DateTime::now();
|
$now = DateTime::now();
|
||||||
var_dump('$cacheLog=');
|
|
||||||
var_dump($cacheLog);
|
|
||||||
if ($cacheLog->isEmpty()) {
|
if ($cacheLog->isEmpty()) {
|
||||||
var_dump('inserting.....');
|
|
||||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||||
'$id' => $key,
|
'$id' => $key,
|
||||||
'resource' => $resource,
|
'resource' => $resource,
|
||||||
|
|
@ -751,17 +748,17 @@ App::shutdown()
|
||||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
|
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($signature !== $cacheLog->getAttribute('signature')) {
|
$cache = new Cache(
|
||||||
$cache = new Cache(
|
new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())
|
||||||
new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())
|
);
|
||||||
);
|
$timestamp = 60 * 60 * 24 * 30;
|
||||||
|
$data = $cache->load($key, $timestamp);
|
||||||
|
if ($signature !== $cacheLog->getAttribute('signature') || empty($data)) {
|
||||||
$cache->save($key, $data['payload']);
|
$cache->save($key, $data['payload']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($project->getId() !== 'console') {
|
if ($project->getId() !== 'console') {
|
||||||
if (!Auth::isPrivilegedUser(Authorization::getRoles())) {
|
if (!Auth::isPrivilegedUser(Authorization::getRoles())) {
|
||||||
$fileSize = 0;
|
$fileSize = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue