Skip to content
Closed
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
23 changes: 23 additions & 0 deletions cmd/msgvault/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ Examples:
}
}

// Rebuild analytics cache if requested.
var cacheErr error
if syncRebuildCache {
analyticsDir := cfg.AnalyticsDir()
fullRebuild := false
if staleness := cacheNeedsBuild(dbPath, analyticsDir); staleness.FullRebuild {
fullRebuild = true
}
result, err := buildCache(dbPath, analyticsDir, fullRebuild)
if err != nil {
cacheErr = err
fmt.Printf("\nCache rebuild failed: %v\n", err)
} else if !result.Skipped {
logger.Info("cache build completed", "exported", result.ExportedCount)
}
}

if len(syncErrors) > 0 {
fmt.Println()
fmt.Println("Errors:")
Expand All @@ -183,6 +200,9 @@ Examples:
return fmt.Errorf("%d account(s) failed to sync: %s",
len(syncErrors), strings.Join(syncErrors, "; "))
}
if cacheErr != nil {
return fmt.Errorf("cache rebuild failed: %w", cacheErr)
}

return nil
},
Expand Down Expand Up @@ -264,6 +284,9 @@ func runIncrementalSync(ctx context.Context, s *store.Store, getOAuthMgr func(st
return nil
}

var syncRebuildCache bool

func init() {
syncIncrementalCmd.Flags().BoolVar(&syncRebuildCache, "rebuild-cache", false, "Rebuild analytics cache after sync")
rootCmd.AddCommand(syncIncrementalCmd)
}
23 changes: 23 additions & 0 deletions cmd/msgvault/cmd/syncfull.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,23 @@ Examples:
}
}

// Rebuild analytics cache if requested.
var cacheErr error
if syncFullRebuildCache {
analyticsDir := cfg.AnalyticsDir()
fullRebuild := false
if staleness := cacheNeedsBuild(dbPath, analyticsDir); staleness.FullRebuild {
fullRebuild = true
}
result, err := buildCache(dbPath, analyticsDir, fullRebuild)
if err != nil {
cacheErr = err
fmt.Printf("\nCache rebuild failed: %v\n", err)
} else if !result.Skipped {
logger.Info("cache build completed", "exported", result.ExportedCount)
}
}

if len(syncErrors) > 0 {
fmt.Println()
fmt.Println("Errors:")
Expand All @@ -175,6 +192,9 @@ Examples:
return fmt.Errorf("%d account(s) failed to sync: %s",
len(syncErrors), strings.Join(syncErrors, "; "))
}
if cacheErr != nil {
return fmt.Errorf("cache rebuild failed: %w", cacheErr)
}

return nil
},
Expand Down Expand Up @@ -422,11 +442,14 @@ func formatDuration(d time.Duration) string {
return fmt.Sprintf("%ds", s)
}

var syncFullRebuildCache bool

func init() {
syncFullCmd.Flags().StringVar(&syncQuery, "query", "", "Gmail search query")
syncFullCmd.Flags().BoolVar(&syncNoResume, "noresume", false, "Force fresh sync (don't resume)")
syncFullCmd.Flags().StringVar(&syncBefore, "before", "", "Only messages before this date (YYYY-MM-DD)")
syncFullCmd.Flags().StringVar(&syncAfter, "after", "", "Only messages after this date (YYYY-MM-DD)")
syncFullCmd.Flags().IntVar(&syncLimit, "limit", 0, "Limit number of messages (for testing)")
syncFullCmd.Flags().BoolVar(&syncFullRebuildCache, "rebuild-cache", false, "Rebuild analytics cache after sync")
rootCmd.AddCommand(syncFullCmd)
}
1 change: 1 addition & 0 deletions internal/sync/incremental.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (s *Syncer) Incremental(ctx context.Context, source *store.Source) (summary
} else {
for i, raw := range rawMessages {
if raw == nil {
s.logger.Warn("failed to fetch message (nil response)", "id", newMsgIDs[i])
checkpoint.ErrorsCount++
continue
}
Expand Down
1 change: 1 addition & 0 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (s *Syncer) processBatch(ctx context.Context, sourceID int64, listResp *gma

for i, raw := range rawMessages {
if raw == nil {
s.logger.Warn("failed to fetch message (nil response)", "id", newIDs[i])
checkpoint.ErrorsCount++
continue
}
Expand Down