Skip to content

Commit 20635ab

Browse files
authored
Don't write execution results to SSBC cache and remove unnecessary additional call to workspace.Diff (#777)
This is the src-cli portion of sourcegraph/sourcegraph#36758. It also optimizes the execution generally, because we run one less workspace.Diff. After this PR, nothing requires us to still write or read execution results from the cache. Since this is a bigger code cleanup/refactor, I filed a separate ticket to address this and put it in sustaining. This PR mostly focuses on getting the Diff call out of the execution and stops to write the unnecessary cache result to the JSON logs so we send less log data.
1 parent 98f49b9 commit 20635ab

File tree

6 files changed

+9
-33
lines changed

6 files changed

+9
-33
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/sourcegraph/go-diff v0.6.1
2121
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
2222
github.com/sourcegraph/scip v0.1.0
23-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220614231716-f73c9fa26c46
23+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220614233452-81dc06f6e96e
2424
github.com/stretchr/testify v1.7.2
2525
golang.org/x/net v0.0.0-20220526153639-5463443f8c37
2626
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ github.com/sourcegraph/log v0.0.0-20220613150728-bb50c87ba841 h1:kiYxuyQ1zSNA4YP
351351
github.com/sourcegraph/log v0.0.0-20220613150728-bb50c87ba841/go.mod h1:A+9F6IicYvBbl2aT0R81lMraKcXjVfdfw352yPe2yJI=
352352
github.com/sourcegraph/scip v0.1.0 h1:kTs0CJaLQvcRZjg+HpGrcJPNX2Tx31+d6szWio3ZOkQ=
353353
github.com/sourcegraph/scip v0.1.0/go.mod h1:/AZ8RvsnRfeCZy232PJuVZqcl9f82fJnYwdWZeU2JCo=
354-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220614231716-f73c9fa26c46 h1:ehDPNEMxvaCKWlV6oGh2jvkcs4bJzL020aSHjxNLSZs=
355-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220614231716-f73c9fa26c46/go.mod h1:Orrt+5wdseAvxsVxgdswYPzJgVkTk0rLlmFHZW61epo=
354+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220614233452-81dc06f6e96e h1:O+XG50CIAdzjuELX2gHhkc9Br1AaAXaOkZWg1YSRFpQ=
355+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220614233452-81dc06f6e96e/go.mod h1:Orrt+5wdseAvxsVxgdswYPzJgVkTk0rLlmFHZW61epo=
356356
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o=
357357
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
358358
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=

internal/batches/executor/run_steps.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func runSteps(ctx context.Context, opts *executionOpts) (result execution.Result
8080
// If we have cached results and don't need to execute any more steps,
8181
// we can quit
8282
if lastStep == len(opts.task.Steps)-1 {
83+
// Build the execution result from the step result.
8384
changes, err := git.ChangesInDiff([]byte(opts.task.CachedResult.Diff))
8485
if err != nil {
8586
return execResult, nil, errors.Wrap(err, "parsing cached step diff")
@@ -100,6 +101,8 @@ func runSteps(ctx context.Context, opts *executionOpts) (result execution.Result
100101
)
101102
}
102103

104+
var lastDiff string
105+
103106
for i := startStep; i < len(opts.task.Steps); i++ {
104107
step := opts.task.Steps[i]
105108

@@ -201,17 +204,11 @@ func runSteps(ctx context.Context, opts *executionOpts) (result execution.Result
201204
}
202205

203206
opts.ui.StepFinished(i+1, stepResult.Diff, result.Files, stepResult.Outputs)
204-
}
205207

206-
opts.ui.CalculatingDiffStarted()
207-
diffOut, err := ws.Diff(ctx)
208-
if err != nil {
209-
return execResult, nil, errors.Wrap(err, "git diff failed")
208+
lastDiff = stepResult.Diff
210209
}
211210

212-
opts.ui.CalculatingDiffFinished()
213-
214-
execResult.Diff = string(diffOut)
211+
execResult.Diff = lastDiff
215212
execResult.ChangedFiles = previousStepResult.Files
216213

217214
return execResult, stepResults, err

internal/batches/executor/ui.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ type StepsExecutionUI interface {
4545

4646
StepOutputWriter(context.Context, *Task, int) StepOutputWriter
4747

48-
CalculatingDiffStarted()
49-
CalculatingDiffFinished()
50-
5148
StepFinished(idx int, diff string, changes *git.Changes, outputs map[string]interface{})
5249
StepFailed(idx int, err error, exitCode int)
5350
}
@@ -68,8 +65,6 @@ func (noop NoopStepsExecUI) StepStarted(step int, runScript string, env map[stri
6865
func (noop NoopStepsExecUI) StepOutputWriter(ctx context.Context, task *Task, step int) StepOutputWriter {
6966
return NoopStepOutputWriter{}
7067
}
71-
func (noop NoopStepsExecUI) CalculatingDiffStarted() {}
72-
func (noop NoopStepsExecUI) CalculatingDiffFinished() {}
7368
func (noop NoopStepsExecUI) StepFinished(idx int, diff string, changes *git.Changes, outputs map[string]interface{}) {
7469
}
7570
func (noop NoopStepsExecUI) StepFailed(idx int, err error, exitCode int) {

internal/batches/ui/json_lines.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ func (ui *JSONLines) ExecutionError(err error) {
175175
var _ executor.JSONCacheWriter = &JSONLines{}
176176

177177
func (ui *JSONLines) WriteExecutionResult(key string, value execution.Result) {
178-
logOperationSuccess(batcheslib.LogEventOperationCacheResult, &batcheslib.CacheResultMetadata{
179-
Key: key,
180-
Value: value,
181-
})
178+
// Noop, we don't need execution results.
182179
}
183180

184181
func (ui *JSONLines) WriteAfterStepResult(key string, value execution.AfterStepResult) {
@@ -363,13 +360,6 @@ func (ui *stepsExecutionJSONLines) StepFailed(step int, err error, exitCode int)
363360
)
364361
}
365362

366-
func (ui *stepsExecutionJSONLines) CalculatingDiffStarted() {
367-
logOperationStart(batcheslib.LogEventOperationTaskCalculatingDiff, &batcheslib.TaskCalculatingDiffMetadata{TaskID: ui.linesTask.ID})
368-
}
369-
func (ui *stepsExecutionJSONLines) CalculatingDiffFinished() {
370-
logOperationSuccess(batcheslib.LogEventOperationTaskCalculatingDiff, &batcheslib.TaskCalculatingDiffMetadata{TaskID: ui.linesTask.ID})
371-
}
372-
373363
func logOperationStart(op batcheslib.LogEventOperation, metadata interface{}) {
374364
logEvent(batcheslib.LogEvent{Operation: op, Status: batcheslib.LogEventStatusStarted, Metadata: metadata})
375365
}

internal/batches/ui/task_exec_tui.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,6 @@ func (ui stepsExecTUI) StepOutputWriter(ctx context.Context, task *executor.Task
471471
return executor.NoopStepOutputWriter{}
472472
}
473473

474-
func (ui stepsExecTUI) CalculatingDiffStarted() {
475-
ui.updateStatusBar("Calculating diff")
476-
}
477-
func (ui stepsExecTUI) CalculatingDiffFinished() {
478-
// noop right now
479-
}
480474
func (ui stepsExecTUI) StepFinished(idx int, diff string, changes *git.Changes, outputs map[string]interface{}) {
481475
// noop right now
482476
}

0 commit comments

Comments
 (0)