Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified bin/aarch64/syncshell-core
Binary file not shown.
Binary file modified bin/x86_64/syncshell-core
Binary file not shown.
46 changes: 42 additions & 4 deletions core/internal/session/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"`
Expand All @@ -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 {
Expand All @@ -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"
Expand Down Expand Up @@ -178,17 +210,20 @@ 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"`
}
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
}
Expand Down Expand Up @@ -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 = &current
} else if s.lastFile != nil && s.lastFileUntil.After(now) {
current := *s.lastFile
activity.Current = &current
}
s.activityMu.Unlock()

Expand Down
7 changes: 4 additions & 3 deletions core/internal/session/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ 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)
nextRefresh = time.Now().Add(s.RefreshInterval())
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)
Expand Down
64 changes: 61 additions & 3 deletions core/internal/session/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions core/internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion hosts/omarchy/OmarchyPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions hosts/omarchy/ui/BodyTabFolders.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packaging/bundled/SHA256SUMS
Original file line number Diff line number Diff line change
@@ -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
Loading