mirror of
https://github.com/HeyPuter/puter.git
synced 2026-09-15 09:45:54 +00:00
More precise cache invalidation in case of item rename
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test (20.x) (push) Has been cancelled
test / test (22.x) (push) Has been cancelled
test / api-test (22.x) (push) Has been cancelled
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test (20.x) (push) Has been cancelled
test / test (22.x) (push) Has been cancelled
test / api-test (22.x) (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import io from '../../lib/socket.io/socket.io.esm.min.js';
|
||||
import * as utils from '../../lib/utils.js';
|
||||
import path from '../../lib/path.js';
|
||||
|
||||
// Constants
|
||||
//
|
||||
@@ -122,9 +123,27 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
||||
// });
|
||||
|
||||
this.socket.on('item.renamed', (item) => {
|
||||
// check original_client_socket_id and if it matches this.socket.id, don't invalidate cache
|
||||
puter._cache.flushall();
|
||||
console.log('Flushed cache for item.renamed');
|
||||
// delete old item from cache
|
||||
puter._cache.del('item:' + item.old_path);
|
||||
// if a directory
|
||||
if(item.is_dir){
|
||||
// delete readdir
|
||||
puter._cache.del('readdir:' + item.old_path);
|
||||
// descendants items
|
||||
const descendants = puter._cache.keys('item:' + item.old_path + '/*');
|
||||
for(const descendant of descendants){
|
||||
console.log('Deleting cache for:', descendant);
|
||||
puter._cache.del(descendant);
|
||||
}
|
||||
// descendants readdirs
|
||||
const descendants_readdir = puter._cache.keys('readdir:' + item.old_path + '/*');
|
||||
for(const descendant of descendants_readdir){
|
||||
console.log('Deleting cache for:', descendant);
|
||||
puter._cache.del(descendant);
|
||||
}
|
||||
}
|
||||
// parent readdir
|
||||
puter._cache.del('readdir:' + path.dirname(item.old_path));
|
||||
});
|
||||
|
||||
this.socket.on('item.removed', (item) => {
|
||||
|
||||
@@ -66,12 +66,12 @@ const readdir = async function (...args) {
|
||||
|
||||
if(resultSize <= MAX_CACHE_SIZE){
|
||||
// UPSERT the cache
|
||||
await puter._cache.set(cacheKey, result);
|
||||
puter._cache.set(cacheKey, result);
|
||||
}
|
||||
|
||||
// set each individual item's cache
|
||||
for(const item of result){
|
||||
await puter._cache.set('item:' + item.path, item);
|
||||
puter._cache.set('item:' + item.path, item);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
|
||||
@@ -39,8 +39,6 @@ const stat = async function (...args) {
|
||||
let cacheKey;
|
||||
if(options.path){
|
||||
cacheKey = 'item:' + options.path;
|
||||
}else if(options.uid){
|
||||
cacheKey = 'item:' + options.uid;
|
||||
}
|
||||
|
||||
if(options.consistency === 'eventual' && !options.returnSubdomains && !options.returnPermissions && !options.returnVersions && !options.returnSize){
|
||||
@@ -65,8 +63,7 @@ const stat = async function (...args) {
|
||||
|
||||
if(resultSize <= MAX_CACHE_SIZE){
|
||||
// UPSERT the cache
|
||||
await puter._cache.set('item:' + result.path, result);
|
||||
await puter._cache.set('item:' + result.uid, result);
|
||||
puter._cache.set(cacheKey, result);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
|
||||
Reference in New Issue
Block a user