From 7b1d819d9dc7b68f60385235d0f0631bf90520d6 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Thu, 14 Aug 2025 16:06:39 +0800 Subject: [PATCH 1/2] opt: only save file path --- utils.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 91dc0dd..c5bf457 100644 --- a/utils.go +++ b/utils.go @@ -56,6 +56,10 @@ type SimpleFileInfo struct { End int64 } +type SimplestFileInfo struct { + Path string +} + // file system tree node type fsNode struct { Name string @@ -322,7 +326,14 @@ func buildIpldGraph(ctx context.Context, // } // log.Info(dirNodeMap) - fileInfo, err := json.Marshal(sfis) + var infos []SimplestFileInfo + for _, info := range sfis { + infos = append(infos, SimplestFileInfo{ + Path: info.Path, + }) + } + + fileInfo, err := json.Marshal(infos) if err != nil { return nil, "", "", err } From 1fd65c8c42b7605519a1f4098b20ad350fa9d5e8 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Thu, 14 Aug 2025 16:11:06 +0800 Subject: [PATCH 2/2] opt: remove repeat code --- utils.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/utils.go b/utils.go index c5bf457..170fcdc 100644 --- a/utils.go +++ b/utils.go @@ -340,11 +340,7 @@ func buildIpldGraph(ctx context.Context, log.Info("++++++++++++ finished to build ipld +++++++++++++") if skipFilename { - type path struct { - Path string `json:"path"` - } - - var list []path + var list []SimplestFileInfo seen := make(map[string]struct{}) for _, f := range sfis { dir := filepath.Dir(f.Path) @@ -353,7 +349,7 @@ func buildIpldGraph(ctx context.Context, } if _, ok := seen[dir]; !ok { seen[dir] = struct{}{} - list = append(list, path{Path: dir}) + list = append(list, SimplestFileInfo{Path: dir}) } }