@@ -10,11 +10,15 @@ import (
1010 "flag"
1111 "io"
1212 "os"
13+ "time"
1314
1415 "github.com/fatih/color"
1516 "github.com/owasp-amass/amass/v4/config"
1617 "github.com/owasp-amass/amass/v4/internal/afmt"
1718 "github.com/owasp-amass/amass/v4/internal/tools"
19+ assetdb "github.com/owasp-amass/asset-db"
20+ "github.com/owasp-amass/asset-db/cache"
21+ "github.com/owasp-amass/asset-db/repository/sqlrepo"
1822 "github.com/owasp-amass/asset-db/triples"
1923)
2024
@@ -138,6 +142,18 @@ func CLIWorkflow(cmdName string, clArgs []string) {
138142 _ , _ = afmt .R .Fprintln (color .Error , "Failed to connect with the database" )
139143 os .Exit (1 )
140144 }
145+ // create a new in-memory SQLite database for performance
146+ cdb , err := assetdb .New (sqlrepo .SQLiteMemory , "" )
147+ if err != nil {
148+ _ , _ = afmt .R .Fprintf (color .Error , "Failed to create an in-memory SQLite database: %v\n " , err )
149+ os .Exit (1 )
150+ }
151+ // Create a cache for the database to speed up the association walk
152+ c , err := cache .New (cdb , db , time .Minute )
153+ if err != nil {
154+ _ , _ = afmt .R .Fprintf (color .Error , "Failed to create a cache for the database: %v\n " , err )
155+ os .Exit (1 )
156+ }
141157
142158 var tris []* triples.Triple
143159 for _ , tstr := range args .Triples {
@@ -157,14 +173,14 @@ func CLIWorkflow(cmdName string, clArgs []string) {
157173 os .Exit (1 )
158174 }
159175
160- results , err := triples .Extract (db , tris )
176+ results , err := triples .Extract (c , tris )
161177 if err != nil {
162178 _ , _ = afmt .R .Fprintf (color .Error , "Failed to extract associations: %v\n " , err )
163179 os .Exit (1 )
164180 }
165181
166- // Marshal with indentation (e.g., 4 spaces)
167- prettyJSON , err := json .MarshalIndent (results , "" , " " )
182+ // Marshal with indentation (e.g., 2 spaces)
183+ prettyJSON , err := json .MarshalIndent (results , "" , " " )
168184 if err != nil {
169185 _ , _ = afmt .R .Fprintf (color .Error , "Error marshaling JSON: %v" , err )
170186 os .Exit (1 )
0 commit comments