diff options
| author | adamdottv <[email protected]> | 2025-05-13 13:08:43 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-13 13:08:43 -0500 |
| commit | 01b6bf5bb7307246cb2cca7f1cbc8aba693941cc (patch) | |
| tree | f47f5aa2b323ce8fea55f6999308486ff790d26e /internal/history | |
| parent | d8f3b606258a5655d73acc94d6cb37b421350817 (diff) | |
| download | opencode-01b6bf5bb7307246cb2cca7f1cbc8aba693941cc.tar.gz opencode-01b6bf5bb7307246cb2cca7f1cbc8aba693941cc.zip | |
chore: refactor db
Diffstat (limited to 'internal/history')
| -rw-r--r-- | internal/history/history.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/internal/history/history.go b/internal/history/history.go index 80fa09d9d..12c94a391 100644 --- a/internal/history/history.go +++ b/internal/history/history.go @@ -113,7 +113,13 @@ func (s *service) CreateVersion(ctx context.Context, sessionID, path, content st if b.Version == InitialVersion && a.Version != InitialVersion { return -1 } - return int(b.CreatedAt - a.CreatedAt) // Fallback to timestamp + // Compare timestamps as strings (ISO format sorts correctly) + if b.CreatedAt > a.CreatedAt { + return 1 + } else if a.CreatedAt > b.CreatedAt { + return -1 + } + return 0 // Equal timestamps }) latestFile := files[0] @@ -362,14 +368,27 @@ func (s *service) Subscribe(ctx context.Context) <-chan pubsub.Event[File] { } func (s *service) fromDBItem(item db.File) File { + // Parse timestamps from ISO strings + createdAt, err := time.Parse(time.RFC3339Nano, item.CreatedAt) + if err != nil { + slog.Error("Failed to parse created_at", "value", item.CreatedAt, "error", err) + createdAt = time.Now() // Fallback + } + + updatedAt, err := time.Parse(time.RFC3339Nano, item.UpdatedAt) + if err != nil { + slog.Error("Failed to parse created_at", "value", item.CreatedAt, "error", err) + updatedAt = time.Now() // Fallback + } + return File{ ID: item.ID, SessionID: item.SessionID, Path: item.Path, Content: item.Content, Version: item.Version, - CreatedAt: time.UnixMilli(item.CreatedAt * 1000), - UpdatedAt: time.UnixMilli(item.UpdatedAt * 1000), + CreatedAt: createdAt, + UpdatedAt: updatedAt, } } |
