From cdcf0e5cb8b6b08ebc3a06eb3eb02d28c01d9aa2 Mon Sep 17 00:00:00 2001 From: wiserain Date: Mon, 8 Jul 2024 18:16:00 +0900 Subject: [PATCH] pikpak: optimize file move by removing unnecessary `readMetaData()` call Previously, the code relied on calling `readMetaData()` after every file move operation. This introduced an unnecessary API call and potentially impacted performance. This change removes the redundant `readMetaData()` call, improving efficiency. --- backend/pikpak/pikpak.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/backend/pikpak/pikpak.go b/backend/pikpak/pikpak.go index 2095a391d..c3f82a079 100644 --- a/backend/pikpak/pikpak.go +++ b/backend/pikpak/pikpak.go @@ -1049,7 +1049,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, return nil, err } - // Create temporary object + // Create temporary object - still missing id, mimeType, gcid, md5sum dstObj, dstLeaf, dstParentID, err := f.createObject(ctx, remote, srcObj.modTime, srcObj.size) if err != nil { return nil, err @@ -1061,7 +1061,12 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, return nil, err } } + // Manually update info of moved object to save API calls dstObj.id = srcObj.id + dstObj.mimeType = srcObj.mimeType + dstObj.gcid = srcObj.gcid + dstObj.md5sum = srcObj.md5sum + dstObj.hasMetaData = true if srcLeaf != dstLeaf { // Rename @@ -1069,16 +1074,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, if err != nil { return nil, fmt.Errorf("move: couldn't rename moved file: %w", err) } - err = dstObj.setMetaData(info) - if err != nil { - return nil, err - } - } else { - // Update info - err = dstObj.readMetaData(ctx) - if err != nil { - return nil, fmt.Errorf("move: couldn't locate moved file: %w", err) - } + return dstObj, dstObj.setMetaData(info) } return dstObj, nil }