Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Speed up event processing #8

Merged
merged 12 commits into from
Apr 24, 2020
Prev Previous commit
Next Next commit
Support file deletion again
  • Loading branch information
ammario committed Apr 24, 2020
commit 423278b43f79f267067e30fc4b13ff6bf3be3876
21 changes: 10 additions & 11 deletions internal/sync/eventcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,33 @@ func (cache eventCache) Add(ev timedEvent) {
cache[ev.Path()] = ev
}

// DirectoryEvents returns the list of events that pertain to directories.
// The set of returns events is disjoint with FileEvents.
func (cache eventCache) DirectoryEvents() []timedEvent {
// SequentialEvents returns the list of events that pertain to directories.
// The set of returned events is disjoint with ConcurrentEvents.
func (cache eventCache) SequentialEvents() []timedEvent {
var r []timedEvent
for _, ev := range cache {
info, err := os.Stat(ev.Path())
if err != nil {
continue
}
if !info.IsDir() {
if err == nil && !info.IsDir() {
continue
}
// Include files that have deleted here.
// It's unclear whether they're files or folders.
r = append(r, ev)

}
return r
}

// FileEvents returns the list of events that pertain to files.
// The set of returns events is disjoint with DirectoryEvents.
func (cache eventCache) FileEvents() []timedEvent {
// ConcurrentEvents returns the list of events that are safe to process after SequentialEvents.
// The set of returns events is disjoint with SequentialEvents.
func (cache eventCache) ConcurrentEvents() []timedEvent {
var r []timedEvent
for _, ev := range cache {
info, err := os.Stat(ev.Path())
if err != nil {
continue
}
if info.IsDir() {
if info.IsDir() {
continue
}
r = append(r, ev)
Expand Down
4 changes: 2 additions & 2 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ func (s Sync) workEventGroup(evs []timedEvent) {
// and then a file is moved to it. AFAIK this dependecy only exists with Directories.
// So, we sequentially process the list of directory Renames and Creates, and then concurrently
// perform all Writes.
for _, ev := range cache.DirectoryEvents() {
for _, ev := range cache.SequentialEvents() {
s.work(ev)
}

var wg sync.WaitGroup
for _, ev := range cache.FileEvents() {
for _, ev := range cache.ConcurrentEvents() {
setConsoleTitle(fmtUpdateTitle(ev.Path()))

wg.Add(1)
Expand Down