diff --git a/CLAUDE.md b/CLAUDE.md index 350cff6..7813518 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -97,10 +97,10 @@ func main() { return } - watcher := storeInstance.Watch("group", "*") - defer storeInstance.Unwatch(watcher) + events := storeInstance.Watch("group") + defer storeInstance.Unwatch("group", events) go func() { - for event := range watcher.Events { + for event := range events { fmt.Println(event.Type, event.Group, event.Key, event.Value) } }() diff --git a/journal.go b/journal.go index dfebbe0..8f471f7 100644 --- a/journal.go +++ b/journal.go @@ -25,8 +25,11 @@ const createJournalEntriesTableSQL = `CREATE TABLE IF NOT EXISTS journal_entries )` var ( - journalBucketPattern = regexp.MustCompile(`bucket:\s*"([^"]+)"`) - journalMeasurementPattern = regexp.MustCompile(`(?:_measurement|measurement)\s*==\s*"([^"]+)"`) + journalBucketPattern = regexp.MustCompile(`bucket:\s*"([^"]+)"`) + journalMeasurementPatterns = []*regexp.Regexp{ + regexp.MustCompile(`(?:_measurement|measurement)\s*==\s*"([^"]+)"`), + regexp.MustCompile(`\[\s*"(?:_measurement|measurement)"\s*\]\s*==\s*"([^"]+)"`), + } ) type journalExecutor interface { @@ -132,7 +135,7 @@ func (storeInstance *Store) queryJournalFlux(flux string) (string, []any, error) builder.WriteString(" AND bucket_name = ?") arguments = append(arguments, bucket) } - if measurement := quotedSubmatch(journalMeasurementPattern, flux); measurement != "" { + if measurement := firstQuotedSubmatch(journalMeasurementPatterns, flux); measurement != "" { builder.WriteString(" AND measurement = ?") arguments = append(arguments, measurement) } @@ -303,6 +306,15 @@ func quotedSubmatch(pattern *regexp.Regexp, value string) string { return match[1] } +func firstQuotedSubmatch(patterns []*regexp.Regexp, value string) string { + for _, pattern := range patterns { + if match := quotedSubmatch(pattern, value); match != "" { + return match + } + } + return "" +} + func regexpSubmatch(pattern *regexp.Regexp, value string, index int) string { match := pattern.FindStringSubmatch(value) if len(match) <= index { diff --git a/store.go b/store.go index a762176..8a26219 100644 --- a/store.go +++ b/store.go @@ -113,7 +113,10 @@ func New(databasePath string, options ...StoreOption) (*Store, error) { } } storeInstance.startBackgroundPurge(purgeContext) - storeInstance.cleanUpOrphanedWorkspaces(defaultWorkspaceStateDirectory) + orphanWorkspaces := storeInstance.RecoverOrphans(defaultWorkspaceStateDirectory) + for _, orphanWorkspace := range orphanWorkspaces { + orphanWorkspace.Discard() + } return storeInstance, nil }