From 4e8f0a0016e5a8e32024afadba35d672470eaf24 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 06:01:00 +0000 Subject: [PATCH] refactor(store): clarify workspace and archive naming Co-Authored-By: Virgil --- compact.go | 36 ++++++++++++++++++------------------ store.go | 5 +---- workspace.go | 2 +- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/compact.go b/compact.go index a837831..f5fd927 100644 --- a/compact.go +++ b/compact.go @@ -20,12 +20,12 @@ type CompactOptions struct { } type compactArchiveEntry struct { - id int64 - bucket string - measurement string - fieldsJSON string - tagsJSON string - committedAt int64 + entryID int64 + bucketName string + measurementName string + fieldsJSON string + tagsJSON string + committedAtUnixMilli int64 } // Compact archives old journal entries as newline-delimited JSON. @@ -65,12 +65,12 @@ func (storeInstance *Store) Compact(options CompactOptions) core.Result { for rows.Next() { var entry compactArchiveEntry if err := rows.Scan( - &entry.id, - &entry.bucket, - &entry.measurement, + &entry.entryID, + &entry.bucketName, + &entry.measurementName, &entry.fieldsJSON, &entry.tagsJSON, - &entry.committedAt, + &entry.committedAtUnixMilli, ); err != nil { return core.Result{Value: core.E("store.Compact", "scan journal row", err), OK: false} } @@ -84,12 +84,12 @@ func (storeInstance *Store) Compact(options CompactOptions) core.Result { } outputPath := compactOutputPath(outputDirectory, format) - createResult := filesystem.Create(outputPath) - if !createResult.OK { - return core.Result{Value: core.E("store.Compact", "create archive file", createResult.Value.(error)), OK: false} + archiveFileResult := filesystem.Create(outputPath) + if !archiveFileResult.OK { + return core.Result{Value: core.E("store.Compact", "create archive file", archiveFileResult.Value.(error)), OK: false} } - file, ok := createResult.Value.(io.WriteCloser) + file, ok := archiveFileResult.Value.(io.WriteCloser) if !ok { return core.Result{Value: core.E("store.Compact", "archive file is not writable", nil), OK: false} } @@ -150,7 +150,7 @@ func (storeInstance *Store) Compact(options CompactOptions) core.Result { if _, err := transaction.Exec( "UPDATE "+journalEntriesTableName+" SET archived_at = ? WHERE entry_id = ?", archivedAt, - entry.id, + entry.entryID, ); err != nil { return core.Result{Value: core.E("store.Compact", "mark journal row archived", err), OK: false} } @@ -177,11 +177,11 @@ func compactArchiveLine(entry compactArchiveEntry) (map[string]any, error) { } return map[string]any{ - "bucket": entry.bucket, - "measurement": entry.measurement, + "bucket": entry.bucketName, + "measurement": entry.measurementName, "fields": fields, "tags": tags, - "committed_at": entry.committedAt, + "committed_at": entry.committedAtUnixMilli, }, nil } diff --git a/store.go b/store.go index 8a26219..a762176 100644 --- a/store.go +++ b/store.go @@ -113,10 +113,7 @@ func New(databasePath string, options ...StoreOption) (*Store, error) { } } storeInstance.startBackgroundPurge(purgeContext) - orphanWorkspaces := storeInstance.RecoverOrphans(defaultWorkspaceStateDirectory) - for _, orphanWorkspace := range orphanWorkspaces { - orphanWorkspace.Discard() - } + storeInstance.cleanUpOrphanedWorkspaces(defaultWorkspaceStateDirectory) return storeInstance, nil } diff --git a/workspace.go b/workspace.go index b5db3c6..ff6fe20 100644 --- a/workspace.go +++ b/workspace.go @@ -44,7 +44,7 @@ type Workspace struct { closed bool } -// NewWorkspace creates a temporary SQLite state file under `.core/state/`. +// NewWorkspace creates a workspace state file under `.core/state/`. // Usage example: `workspace, err := storeInstance.NewWorkspace("scroll-session-2026-03-30")` func (storeInstance *Store) NewWorkspace(name string) (*Workspace, error) { validation := core.ValidateName(name) -- 2.45.3