diff --git a/CHANGELOG.md b/CHANGELOG.md index e35caec1..d7fc45f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Notable changes to Syncshell and its shell adapters are documented here. ## Unreleased +- keep the syncing file name visible during bulk syncs: the core no longer + stalls for up to minutes on lookups and rescans for files Syncthing already + reported, and the Omarchy folder card no longer rebuilds on each update - fit the monochrome icons' view box to the mark so the Omarchy 4.5 bar no longer shrinks them below its built-in icons - replace the experimental DMS adapter with native folder, device, sharing diff --git a/bin/aarch64/syncshell-core b/bin/aarch64/syncshell-core index 1f0348d0..1d4a3906 100755 Binary files a/bin/aarch64/syncshell-core and b/bin/aarch64/syncshell-core differ diff --git a/bin/x86_64/syncshell-core b/bin/x86_64/syncshell-core index f7a0a5b3..2fa10b63 100755 Binary files a/bin/x86_64/syncshell-core and b/bin/x86_64/syncshell-core differ diff --git a/core/internal/session/activity.go b/core/internal/session/activity.go index 46d304ec..007c8356 100644 --- a/core/internal/session/activity.go +++ b/core/internal/session/activity.go @@ -15,6 +15,11 @@ const ( activityHold = 10 * time.Second activityCycle = 2500 * time.Millisecond maxActivity = 12 + // Syncthing lists a pulled file in LocalIndexUpdated seconds after ItemFinished. + finishedItemMemory = 30 * time.Second + maxFinishedItems = 8192 + // Files often finish in the batch that started them; keep the last name briefly. + lastFileHold = 1500 * time.Millisecond ) type activityRecord struct { @@ -42,7 +47,7 @@ func (s *Session) processActivityEvents( case "ItemStarted": changed = s.itemStarted(event, now) || changed case "ItemFinished": - changed = s.itemFinished(event) || changed + changed = s.itemFinished(event, now) || changed case "DeviceDisconnected": changed = s.deviceDisconnected(event) || changed } @@ -102,6 +107,21 @@ func (s *Session) remoteProgress(event syncthing.Event, now time.Time) bool { return changed } +// rememberFinished lets localIndex skip files the event stream already reported. +func (s *Session) rememberFinished(folderID, path string, now time.Time) { + if s.finishedItems == nil || len(s.finishedItems) >= maxFinishedItems { + for key, expires := range s.finishedItems { + if !expires.After(now) { + delete(s.finishedItems, key) + } + } + if s.finishedItems == nil || len(s.finishedItems) >= maxFinishedItems { + s.finishedItems = make(map[string]time.Time) + } + } + s.finishedItems[folderID+"\x00"+path] = now.Add(finishedItemMemory) +} + func (s *Session) localIndex(ctx context.Context, event syncthing.Event, now time.Time) bool { var data struct { Folder string `json:"folder"` @@ -111,7 +131,16 @@ func (s *Session) localIndex(ctx context.Context, event syncthing.Event, now tim return false } changed := false - for _, name := range data.Filenames[:min(len(data.Filenames), 16)] { + names := make([]string, 0, 16) + for _, name := range data.Filenames { + if expires, ok := s.finishedItems[data.Folder+"\x00"+name]; ok && expires.After(now) { + continue + } + if names = append(names, name); len(names) == 16 { + break + } + } + for _, name := range names { info, err := s.currentFileInfo(ctx, data.Folder, name) entry := info.Local if entry == nil { @@ -122,7 +151,10 @@ func (s *Session) localIndex(ctx context.Context, event syncthing.Event, now tim continue } if fileType(entry.Type) == "directory" && !entry.Deleted { - _ = s.client.RescanSubdirectory(ctx, data.Folder, name) + // Syncthing answers only once the scan ends, which waits for any pull. + go func(folderID, subdirectory string) { + _ = s.client.RescanSubdirectory(ctx, folderID, subdirectory) + }(data.Folder, name) continue } action := "syncing" @@ -178,7 +210,7 @@ func (s *Session) itemStarted(event syncthing.Event, now time.Time) bool { return s.storeActivity(data.Folder, data.Item, action, "", now) } -func (s *Session) itemFinished(event syncthing.Event) bool { +func (s *Session) itemFinished(event syncthing.Event, now time.Time) bool { var data struct { Folder string `json:"folder"` Item string `json:"item"` @@ -186,9 +218,12 @@ func (s *Session) itemFinished(event syncthing.Event) bool { if json.Unmarshal(event.Data, &data) != nil { return false } + s.rememberFinished(data.Folder, data.Item, now) changed := false for key, record := range s.activityRecords { if record.activity.FolderID == data.Folder && record.activity.Path == data.Item { + last := record.activity + s.lastFile, s.lastFileUntil = &last, now.Add(lastFileHold) delete(s.activityRecords, key) changed = true } @@ -274,6 +309,9 @@ func (s *Session) publishActivity(advance bool, now time.Time) PublishedSnapshot if len(activity.Files) > 0 { current := activity.Files[s.activityIndex] activity.Current = ¤t + } else if s.lastFile != nil && s.lastFileUntil.After(now) { + current := *s.lastFile + activity.Current = ¤t } s.activityMu.Unlock() diff --git a/core/internal/session/events.go b/core/internal/session/events.go index 576e112b..05521708 100644 --- a/core/internal/session/events.go +++ b/core/internal/session/events.go @@ -90,6 +90,10 @@ func (s *Session) eventLoop(ctx context.Context, updates chan PublishedSnapshot) if len(events) > 0 { gap := eventDiscontinuity(cursor, events) cursor = events[len(events)-1].ID + // Report files first: a refresh can take a second under load. + if s.processActivityEvents(ctx, events, time.Now()) { + emitLatest(updates, s.publishActivity(false, time.Now())) + } if gap || requiresHydration(events) { published, _ := s.Refresh(ctx) emitLatest(updates, published) @@ -97,9 +101,6 @@ func (s *Session) eventLoop(ctx context.Context, updates chan PublishedSnapshot) nextLifecycle = time.Now().Add(s.ProbeInterval()) nextTelemetry = time.Now().Add(deviceTelemetryInterval) } - if s.processActivityEvents(ctx, events, time.Now()) { - emitLatest(updates, s.publishActivity(false, time.Now())) - } } s.reconcileScheduled(ctx, updates, time.Now(), &nextRefresh, &nextLifecycle, &nextTelemetry, &nextActivity) diff --git a/core/internal/session/events_test.go b/core/internal/session/events_test.go index db648c5d..094c9049 100644 --- a/core/internal/session/events_test.go +++ b/core/internal/session/events_test.go @@ -172,6 +172,59 @@ func TestActivityNormalizationRotationAndCleanup(t *testing.T) { } } +func TestLastFileStaysVisibleBriefly(t *testing.T) { + now := time.Unix(100, 0) + coreSession := &Session{ + activityRecords: make(map[string]activityRecord), + current: PublishedSnapshot{Revision: 1}, + } + batch := []syncthing.Event{ + {Type: "ItemStarted", Data: []byte(`{"folder":"folder","item":"dir/small.txt","action":"update"}`)}, + {Type: "ItemFinished", Data: []byte(`{"folder":"folder","item":"dir/small.txt"}`)}, + } + coreSession.processActivityEvents(context.Background(), batch, now) + shown := coreSession.publishActivity(false, now) + if shown.State.Activity.Current == nil || shown.State.Activity.Current.Detail != "small.txt" { + t.Fatalf("batched file never reached the panel: %#v", shown.State.Activity) + } + if len(shown.State.Activity.Files) != 0 { + t.Fatalf("finished file still counted as active: %#v", shown.State.Activity.Files) + } + cleared := coreSession.publishActivity(false, now.Add(lastFileHold+time.Millisecond)) + if cleared.State.Activity.Current != nil { + t.Fatalf("finished file outlived its hold: %#v", cleared.State.Activity.Current) + } +} + +func TestLocalIndexSkipsFilesAlreadyReportedFinished(t *testing.T) { + api := &actionAPI{folders: map[string]syncthing.Folder{}, + devices: []syncthing.Device{{DeviceID: "LOCAL"}}, + pending: syncthing.PendingFolders{}, theme: "default"} + coreSession := newActionSession(t, api) + if _, err := coreSession.Refresh(context.Background()); err != nil { + t.Fatal(err) + } + now := time.Unix(100, 0) + events := []syncthing.Event{ + {Type: "ItemFinished", Data: []byte(`{"folder":"folder","item":"directory"}`)}, + {Type: "LocalIndexUpdated", Data: []byte(`{"folder":"folder","filenames":["directory"]}`)}, + } + coreSession.processActivityEvents(context.Background(), events, now) + time.Sleep(50 * time.Millisecond) + if got := api.rescanCount(); got != 0 { + t.Fatalf("pulled directory was rescanned %d times", got) + } + later := []syncthing.Event{{Type: "LocalIndexUpdated", + Data: []byte(`{"folder":"folder","filenames":["directory"]}`)}} + coreSession.processActivityEvents(context.Background(), later, now.Add(finishedItemMemory+time.Second)) + for deadline := time.Now().Add(2 * time.Second); api.rescanCount() != 1; { + if time.Now().After(deadline) { + t.Fatalf("local directory change was not rescanned: rescans=%d", api.rescanCount()) + } + time.Sleep(5 * time.Millisecond) + } +} + func TestLocalIndexUsesCurrentFileInformation(t *testing.T) { api := &actionAPI{folders: map[string]syncthing.Folder{}, devices: []syncthing.Device{{DeviceID: "LOCAL"}}, @@ -187,9 +240,14 @@ func TestLocalIndexUsesCurrentFileInformation(t *testing.T) { t.Fatal("local index did not change activity") } published := coreSession.publishActivity(false, now) - if len(published.State.Activity.Files) != 2 || api.rescanCount() != 1 { - t.Fatalf("unexpected indexed activity: %#v rescans=%d", - published.State.Activity, api.rescanCount()) + if len(published.State.Activity.Files) != 2 { + t.Fatalf("unexpected indexed activity: %#v", published.State.Activity) + } + for deadline := time.Now().Add(2 * time.Second); api.rescanCount() != 1; { + if time.Now().After(deadline) { + t.Fatalf("directory was not rescanned: rescans=%d", api.rescanCount()) + } + time.Sleep(5 * time.Millisecond) } actions := make(map[string]string) for _, activity := range published.State.Activity.Files { diff --git a/core/internal/session/session.go b/core/internal/session/session.go index 8814eb7d..d2be8d4e 100644 --- a/core/internal/session/session.go +++ b/core/internal/session/session.go @@ -66,6 +66,9 @@ type Session struct { eventsOnce sync.Once activityMu sync.Mutex activityRecords map[string]activityRecord + finishedItems map[string]time.Time + lastFile *Activity + lastFileUntil time.Time activityIndex int externalLatched bool deviceSamples map[string]deviceTransferSample diff --git a/hosts/omarchy/OmarchyPanel.qml b/hosts/omarchy/OmarchyPanel.qml index d96368d7..7c2d85d4 100644 --- a/hosts/omarchy/OmarchyPanel.qml +++ b/hosts/omarchy/OmarchyPanel.qml @@ -62,7 +62,6 @@ Panel { property bool noticeShown: false readonly property var folderRows: buildFolderRows() readonly property var currentFolderRow: folderById(currentFolderId) - readonly property var visibleFolderRows: currentFolderRow ? [currentFolderRow] : [] readonly property var pendingOfferRows: pendingOfferOptions() readonly property double trackedBytes: folderTotal("globalBytes") readonly property int trackedFiles: folderTotal("globalFiles") diff --git a/hosts/omarchy/ui/BodyTabFolders.qml b/hosts/omarchy/ui/BodyTabFolders.qml index 57d23324..6dd71a10 100644 --- a/hosts/omarchy/ui/BodyTabFolders.qml +++ b/hosts/omarchy/ui/BodyTabFolders.qml @@ -197,10 +197,11 @@ Column { Repeater { id: folderCards - model: root.controller.visibleFolderRows + // Keep one card alive: its row flickers if every status update rebuilds it. + model: root.controller.currentFolderRow ? 1 : 0 BodyTabFoldersCard { - required property var modelData + readonly property var modelData: root.controller.currentFolderRow width: parent.width folder: modelData controller: root.controller diff --git a/packaging/bundled/SHA256SUMS b/packaging/bundled/SHA256SUMS index fa721098..a81fddad 100644 --- a/packaging/bundled/SHA256SUMS +++ b/packaging/bundled/SHA256SUMS @@ -1,3 +1,3 @@ 314a89c32525c5b746f50a52b65967ed301e11f12bbbf5f3d44e387a10d540fc bin/syncshell-core -560a83155dd0a5e4b48be906ef6079f3da7a3bd5f2f16661c575e59c8078323d bin/x86_64/syncshell-core -937f41ee78b95903fcb75955f6d3c42efeaf83e0427087d987b3b4d4703c806f bin/aarch64/syncshell-core +583506f451c0d0b5d090b43e4e7a6a3a760e256b1342fe08bd88a37831b6c25e bin/x86_64/syncshell-core +1b9b1efa912ed1b96420d5c2c6ab70bb6d4b194d5f0930d6916e6d23cf9edf02 bin/aarch64/syncshell-core