Compare commits

..

3 Commits

Author SHA1 Message Date
65739c9307 createDir cache fix 2021-08-16 22:16:42 +02:00
c20748aef1 added createDir mutation 2021-08-16 19:57:48 +02:00
6e323a0e4f invalidate cache on move mutation 2021-08-16 14:58:03 +02:00
3 changed files with 66 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

@@ -96,8 +96,39 @@ func moveMutation(ctx context.Context, src, dest string) (*File, error) {
return nil, err return nil, err
} }
invalidateCache(ctx, info.Key)
return &File{ return &File{
ID: info.Key, ID: info.Key,
}, nil }, nil
} }
func createDirectory(ctx context.Context, path string) (*Directory, error) {
s3Client, ok := ctx.Value("s3Client").(*minio.Client)
if !ok {
return nil, fmt.Errorf("Failed to get s3Client from context")
}
if !strings.HasSuffix(path, "/") {
path += "/"
}
info, err := s3Client.PutObject(ctx, bucketName, path, strings.NewReader(""), 0, minio.PutObjectOptions{
ContentType: "application/x-directory",
})
if err != nil {
return nil, err
}
// Invalidate cache
// TODO: check error
invalidateCacheForDir(ctx, info.Key)
return &Directory{
ID: info.Key,
}, nil
}

View File

@@ -146,6 +146,24 @@ func graphqlSchema() (graphql.Schema, error) {
return moveMutation(p.Context, src, dest) return moveMutation(p.Context, src, dest)
}, },
}, },
"createDir": &graphql.Field{
Type: graphql.NewNonNull(graphqlDirType),
Args: graphql.FieldConfigArgument{
"path": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.ID),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
path, ok := p.Args["path"].(string)
if !ok {
return nil, fmt.Errorf("Failed to parse args")
}
log.Debug("mutation 'createDir': ", path)
return createDirectory(p.Context, path)
},
},
} }
rootQuery := graphql.ObjectConfig{ rootQuery := graphql.ObjectConfig{