Merge pull request #4356 from owncloud/code-improvements

add storageID to the special items, improve code
This commit is contained in:
Michael Barz
2022-08-08 16:43:14 +02:00
committed by GitHub
3 changed files with 12 additions and 5 deletions
@@ -0,0 +1,5 @@
Enhancement: Use storageID when requesting special items
We need to use the storageID when requesting the special items of a space to spare a registry lookup and improve the performance
https://github.com/owncloud/ocis/pull/4356
+4 -2
View File
@@ -227,6 +227,8 @@ func (g Graph) GetExtendedSpaceProperties(ctx context.Context, baseURL *url.URL,
for _, itemName := range names { for _, itemName := range names {
if itemID, ok := metadata[itemName]; ok { if itemID, ok := metadata[itemName]; ok {
rid, _ := storagespace.ParseID(string(itemID.Value)) rid, _ := storagespace.ParseID(string(itemID.Value))
// add the storageID of the space, all drive items of this space belong to the same storageID
rid.StorageId = space.GetRoot().GetStorageId()
spaceItem := g.getSpecialDriveItem(ctx, rid, itemName, baseURL, space) spaceItem := g.getSpecialDriveItem(ctx, rid, itemName, baseURL, space)
if spaceItem != nil { if spaceItem != nil {
spaceItems = append(spaceItems, *spaceItem) spaceItems = append(spaceItems, *spaceItem)
@@ -244,12 +246,12 @@ func (g Graph) getSpecialDriveItem(ctx context.Context, id storageprovider.Resou
spaceItem, err := g.getDriveItem(ctx, id) spaceItem, err := g.getDriveItem(ctx, id)
if err != nil { if err != nil {
g.logger.Error().Err(err).Str("ID", id.OpaqueId).Msg("Could not get readme Item") g.logger.Error().Err(err).Str("ID", id.OpaqueId).Str("name", itemName).Msg("Could not get item info")
return nil return nil
} }
itemPath, err := g.getPathForResource(ctx, id) itemPath, err := g.getPathForResource(ctx, id)
if err != nil { if err != nil {
g.logger.Error().Err(err).Str("ID", id.OpaqueId).Msg("Could not get readme path") g.logger.Error().Err(err).Str("ID", id.OpaqueId).Str("name", itemName).Msg("Could not get item path")
return nil return nil
} }
spaceItem.SpecialFolder = &libregraph.SpecialFolder{Name: libregraph.PtrString(itemName)} spaceItem.SpecialFolder = &libregraph.SpecialFolder{Name: libregraph.PtrString(itemName)}
+3 -3
View File
@@ -434,8 +434,7 @@ func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*stor
if err != nil { if err != nil {
return nil, err return nil, err
} }
lReq := &storageprovider.ListStorageSpacesRequest{
res, err := client.ListStorageSpaces(ctx, &storageprovider.ListStorageSpacesRequest{
Opaque: &types.Opaque{Map: map[string]*types.OpaqueEntry{ Opaque: &types.Opaque{Map: map[string]*types.OpaqueEntry{
"permissions": { "permissions": {
Decoder: "json", Decoder: "json",
@@ -447,7 +446,8 @@ func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*stor
}, },
}}, }},
Filters: filters, Filters: filters,
}) }
res, err := client.ListStorageSpaces(ctx, lReq)
return res, err return res, err
} }