Skip to content

Commit 593b442

Browse files
authored
feat: ES-198 enhance performance when loading big projects (#93)
* feat: Use virtualization, improve performance in result mapper * feat: Improve code viewer * fix: editor scroll sync * feat: improve sidebar * feat: add loading state to results sidebar * feat: add usequery cache, create reusable useResults hook * feat: cache results in memory * feat: more caching * feat: refresh results cache after changing config * feat: small improvements * feat: fix unit tests
1 parent 1816818 commit 593b442

35 files changed

+869
-300
lines changed

app.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ func (a *App) initializeMenu() {
132132

133133
// View menu
134134
ViewMenu := AppMenu.AddSubmenu("View")
135-
ViewMenu.AddText("Sync Scroll Position", keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey), func(cd *menu.CallbackData) {})
135+
ViewMenu.AddText("Sync Scroll Position", keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey), func(cd *menu.CallbackData) {
136+
runtime.EventsEmit(a.ctx, string(entities.ActionToggleSyncScrollPosition))
137+
})
136138

137139
// Scan menu
138140
ScanMenu := AppMenu.AddSubmenu("Scan")

backend/entities/keyboard.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const (
5353
ActionReplaceComponentWithComments Action = "replaceComponentWithComments"
5454

5555
// View
56-
ActionSyncScrollPosition Action = "toggleSyncScrollPosition"
56+
ActionToggleSyncScrollPosition Action = "toggleSyncScrollPosition"
5757
ActionShowKeyboardShortcutsModal Action = "showKeyboardShortcutsModal"
5858

5959
// Scan
@@ -105,7 +105,7 @@ var AllShortcutActions = []struct {
105105
{ActionReplaceFileWithComments, "ReplaceFileWithComments"},
106106
{ActionReplaceComponentWithoutComments, "ReplaceComponentWithoutComments"},
107107
{ActionReplaceComponentWithComments, "ReplaceComponentWithComments"},
108-
{ActionSyncScrollPosition, "ToggleSyncScrollPosition"},
108+
{ActionToggleSyncScrollPosition, "ToggleSyncScrollPosition"},
109109
{ActionShowKeyboardShortcutsModal, "ShowKeyboardShortcutsModal"},
110110
{ActionScanWithOptions, "ScanWithOptions"},
111111
}
@@ -296,8 +296,8 @@ var DefaultShortcuts = []Shortcut{
296296
Description: "Sync the scroll position of the editors",
297297
Accelerator: keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey),
298298
Keys: "shift+mod+e",
299-
Group: GroupActions,
300-
Action: ActionReplaceComponentWithComments,
299+
Group: GroupView,
300+
Action: ActionToggleSyncScrollPosition,
301301
},
302302

303303
// Scan

backend/entities/mocks/mock_FileWatcher.go

Lines changed: 122 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/entities/result.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ var (
3939
)
4040

4141
type Result struct {
42-
Path string `json:"path"`
43-
MatchType string `json:"match_type"`
44-
Purl *[]string `json:"purl,omitempty"`
45-
ComponentName string `json:"component"`
46-
Matches []Match `json:"matches,omitempty"`
42+
Path string `json:"path"`
43+
MatchType string `json:"match_type"`
44+
Purl *[]string `json:"purl,omitempty"`
45+
ComponentName string `json:"component"`
46+
Matches []Component `json:"matches,omitempty"`
4747
}
4848

4949
func NewResult() *Result {
@@ -96,14 +96,6 @@ type ResultLicense struct {
9696
URL string `json:"url,omitempty"`
9797
}
9898

99-
type Match struct {
100-
ID string `json:"id"`
101-
Purl []string `json:"purl,omitempty"`
102-
ComponentName string `json:"component"`
103-
Matched string `json:"matched,omitempty"`
104-
Licenses []ResultLicense `json:"licenses,omitempty"`
105-
}
106-
10799
type MatchType string
108100

109101
const (

backend/entities/watcher.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package entities
2+
3+
import (
4+
"github.com/fsnotify/fsnotify"
5+
"github.com/rs/zerolog/log"
6+
)
7+
8+
type FileWatcher interface {
9+
Start() error
10+
Close() error
11+
}
12+
13+
type fsNotifyWatcher struct {
14+
watcher *fsnotify.Watcher
15+
path string
16+
onFileChange func()
17+
}
18+
19+
func NewFsNotifyWatcher(path string, onFileChange func()) (FileWatcher, error) {
20+
watcher, err := fsnotify.NewWatcher()
21+
if err != nil {
22+
return nil, err
23+
}
24+
return &fsNotifyWatcher{
25+
watcher: watcher,
26+
path: path,
27+
onFileChange: onFileChange,
28+
}, nil
29+
}
30+
31+
func (w *fsNotifyWatcher) Start() error {
32+
if err := w.watcher.Add(w.path); err != nil {
33+
log.Error().Err(err).Msgf("Error watching file: %s", w.path)
34+
return w.Close()
35+
}
36+
37+
go func() {
38+
for {
39+
select {
40+
case event, ok := <-w.watcher.Events:
41+
if !ok {
42+
return
43+
}
44+
if event.Op&fsnotify.Write == fsnotify.Write {
45+
w.onFileChange()
46+
}
47+
case err, ok := <-w.watcher.Errors:
48+
if !ok {
49+
return
50+
}
51+
log.Error().Err(err).Msg("Watcher error")
52+
}
53+
}
54+
}()
55+
56+
return nil
57+
}
58+
59+
func (w *fsNotifyWatcher) Close() error {
60+
return w.watcher.Close()
61+
}

0 commit comments

Comments
 (0)