Skip to content

Commit 161527f

Browse files
authored
Simplify caching logic in 'src batch exec' (#653)
This is part of https://github.com/sourcegraph/sourcegraph/issues/26929 and simplifies the caching-related logic in `src batch exec` to only what's needed: checking for per-step cache results. Since server-side batch changes use server-side caching for changeset specs we don't need to check for changeset specs.
1 parent bd77e8c commit 161527f

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

cmd/src/batch_exec.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,26 +159,16 @@ func executeBatchSpecInWorkspaces(ctx context.Context, ui *ui.JSONLines, opts ex
159159
TempDir: opts.flags.tempDir,
160160
})
161161

162-
ui.CheckingCache()
162+
// `src batch exec` uses server-side caching for changeset specs, so we
163+
// only need to call `CheckStepResultsCache` to make sure that per-step cache entries
164+
// are loaded and set on the tasks.
163165
tasks := svc.BuildTasks(ctx, batchSpec, repoWorkspaces)
164-
var (
165-
specs []*batcheslib.ChangesetSpec
166-
uncachedTasks []*executor.Task
167-
)
168-
// TODO: We don't need to support clear cache here at all.
169-
if opts.flags.clearCache {
170-
coord.ClearCache(ctx, tasks)
171-
uncachedTasks = tasks
172-
} else {
173-
uncachedTasks, specs, err = coord.CheckCache(ctx, tasks)
174-
if err != nil {
175-
return err
176-
}
166+
if err := coord.CheckStepResultsCache(ctx, tasks); err != nil {
167+
return err
177168
}
178-
ui.CheckingCacheSuccess(len(specs), len(uncachedTasks))
179169

180170
taskExecUI := ui.ExecutingTasks(*verbose, opts.flags.parallelism)
181-
freshSpecs, _, err := coord.Execute(ctx, uncachedTasks, batchSpec, taskExecUI)
171+
specs, _, err := coord.Execute(ctx, tasks, batchSpec, taskExecUI)
182172
if err == nil || opts.flags.skipErrors {
183173
if err == nil {
184174
taskExecUI.Success()
@@ -191,9 +181,6 @@ func executeBatchSpecInWorkspaces(ctx context.Context, ui *ui.JSONLines, opts ex
191181
return err
192182
}
193183
}
194-
195-
specs = append(specs, freshSpecs...)
196-
197184
ids := make([]graphql.ChangesetSpecID, len(specs))
198185

199186
ui.UploadingChangesetSpecs(len(specs))

internal/batches/executor/coordinator.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ func (c *Coordinator) CheckCache(ctx context.Context, tasks []*Task) (uncached [
103103
return uncached, specs, nil
104104
}
105105

106+
// CheckStepResultsCache checks the cache for each Task, but only for cached
107+
// step results. This is used by `src batch exec` when executing server-side.
108+
func (c *Coordinator) CheckStepResultsCache(ctx context.Context, tasks []*Task) error {
109+
for _, t := range tasks {
110+
if err := c.loadCachedStepResults(ctx, t); err != nil {
111+
return err
112+
}
113+
}
114+
return nil
115+
}
116+
106117
func (c *Coordinator) ClearCache(ctx context.Context, tasks []*Task) error {
107118
for _, task := range tasks {
108119
cacheKey := task.cacheKey()

0 commit comments

Comments
 (0)