createDir cache fix

This commit is contained in:
Niklas 2021-08-16 22:16:42 +02:00
parent c20748aef1
commit 65739c9307
2 changed files with 21 additions and 0 deletions

View File

@ -34,3 +34,20 @@ func getPathFromId(id string) string {
func getFilenameFromID(id string) string { func getFilenameFromID(id string) string {
return filepath.Base(id) return filepath.Base(id)
} }
func invalidateCacheForDir(ctx context.Context, path string) error {
loader, ok := ctx.Value("loader").(map[string]*dataloader.Loader)
if !ok {
return fmt.Errorf("Failed to get loader from context")
}
log.Debug("Invalidate cache for dir: ", path)
// FIXME: only clear required ids
loader["getFile"].ClearAll()
loader["listObjects"].ClearAll()
loader["getFiles"].ClearAll()
loader["getDirs"].ClearAll()
return nil
}

View File

@ -123,6 +123,10 @@ func createDirectory(ctx context.Context, path string) (*Directory, error) {
return nil, err return nil, err
} }
// Invalidate cache
// TODO: check error
invalidateCacheForDir(ctx, info.Key)
return &Directory{ return &Directory{
ID: info.Key, ID: info.Key,
}, nil }, nil