Skip to content

Commit

Permalink
chore: use hashed in IDs for reducing bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
gabotechs committed Dec 25, 2023
1 parent 49c700c commit 13472ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/entropy/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func makeGraph(dt *dep_tree.DepTree[language.FileInfo], parser language.NodePars
filepath := parser.Display(node)
dirName := path.Dir(filepath)
out.Nodes = append(out.Nodes, Node{
Id: node.Id,
Id: utils.Hash(node.Id),
FileName: path.Base(filepath),
DirName: dirName + "/",
Loc: node.Data.Loc,
Expand All @@ -68,23 +68,23 @@ func makeGraph(dt *dep_tree.DepTree[language.FileInfo], parser language.NodePars

for _, to := range dt.Graph.FromId(node.Id) {
out.Links = append(out.Links, Link{
From: node.Id,
To: to.Id,
From: utils.Hash(node.Id),
To: utils.Hash(to.Id),
})
}

for _, parentFolder := range splitFullPaths(dirName) {
out.Links = append(out.Links, Link{
From: node.Id,
To: parentFolder,
From: utils.Hash(node.Id),
To: utils.Hash(parentFolder),
IsDir: true,
})
if _, ok := addedFolders[parentFolder]; ok {
continue
} else {
addedFolders[parentFolder] = true
out.Nodes = append(out.Nodes, Node{
Id: parentFolder,
Id: utils.Hash(parentFolder),
IsDir: true,
})
}
Expand All @@ -93,8 +93,8 @@ func makeGraph(dt *dep_tree.DepTree[language.FileInfo], parser language.NodePars

for el := dt.Cycles.Front(); el != nil; el = el.Next() {
out.Links = append(out.Links, Link{
From: el.Key[0],
To: el.Key[1],
From: utils.Hash(el.Key[0]),
To: utils.Hash(el.Key[1]),
IsCyclic: true,
})
}
Expand Down
12 changes: 12 additions & 0 deletions internal/utils/hash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package utils

import (
"crypto/md5"

Check failure on line 4 in internal/utils/hash.go

View workflow job for this annotation

GitHub Actions / lint

G501: Blocklisted import crypto/md5: weak cryptographic primitive (gosec)
"fmt"
)

func hash(text string) string {
return fmt.Sprintf("%x", md5.Sum([]byte(text)))

Check failure on line 9 in internal/utils/hash.go

View workflow job for this annotation

GitHub Actions / lint

G401: Use of weak cryptographic primitive (gosec)
}

var Hash = Cached(hash)

0 comments on commit 13472ab

Please sign in to comment.