mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-14 05:05:09 +08:00
fix: reverse snapshot order to preserve capture sequence during stable sort
This commit is contained in:
@@ -324,11 +324,13 @@ func buildCaptureChains(snapshot []devcapture.Entry) []captureChain {
|
||||
return nil
|
||||
}
|
||||
ordered := make([]devcapture.Entry, len(snapshot))
|
||||
copy(ordered, snapshot)
|
||||
// devcapture snapshots are newest-first because the store prepends entries.
|
||||
// Reverse once so equal-second timestamps can preserve the actual capture
|
||||
// order (completion before continue) under the stable CreatedAt sort below.
|
||||
for i := range snapshot {
|
||||
ordered[len(snapshot)-1-i] = snapshot[i]
|
||||
}
|
||||
sort.SliceStable(ordered, func(i, j int) bool {
|
||||
if ordered[i].CreatedAt == ordered[j].CreatedAt {
|
||||
return ordered[i].ID < ordered[j].ID
|
||||
}
|
||||
return ordered[i].CreatedAt < ordered[j].CreatedAt
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user