Index prior audio inputs for reuse
This commit is contained in:
@@ -231,7 +231,12 @@ no timing or production-size assumption is required.
|
|||||||
|
|
||||||
**Priority:** P3
|
**Priority:** P3
|
||||||
|
|
||||||
**Status:** For consideration
|
**Status:** Complete
|
||||||
|
|
||||||
|
Prior audio records are indexed once by cleaned destination, retaining the first
|
||||||
|
audio match. Existing identity/hash/download checks remain unchanged. Verified
|
||||||
|
S3 reuse, missing-file replacement, unrelated kinds, and duplicate-record
|
||||||
|
precedence with `go test ./internal/stage ./internal/audio`.
|
||||||
|
|
||||||
**Stage:** 17.
|
**Stage:** 17.
|
||||||
|
|
||||||
|
|||||||
@@ -433,15 +433,20 @@ func materializeS3AudioInputs(ctx context.Context, env *Env, m *manifest.Manifes
|
|||||||
return s3AudioMaterializationStats{}, fmt.Errorf("create work audio directory %q: %w", workAudioDir, err)
|
return s3AudioMaterializationStats{}, fmt.Errorf("create work audio directory %q: %w", workAudioDir, err)
|
||||||
}
|
}
|
||||||
stats := s3AudioMaterializationStats{}
|
stats := s3AudioMaterializationStats{}
|
||||||
|
priorByPath := make(map[string]*manifest.InputRecord)
|
||||||
|
for i := range m.Inputs {
|
||||||
|
record := &m.Inputs[i]
|
||||||
|
if record.Kind != "audio" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
key := filepath.Clean(record.Path)
|
||||||
|
if _, exists := priorByPath[key]; !exists {
|
||||||
|
priorByPath[key] = record
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, obj := range audioObjects {
|
for _, obj := range audioObjects {
|
||||||
workPath := filepath.Join(workAudioDir, path.Base(obj.Key))
|
workPath := filepath.Join(workAudioDir, path.Base(obj.Key))
|
||||||
var prior *manifest.InputRecord
|
prior := priorByPath[filepath.Clean(workPath)]
|
||||||
for i := range m.Inputs {
|
|
||||||
if m.Inputs[i].Kind == "audio" && filepath.Clean(m.Inputs[i].Path) == filepath.Clean(workPath) {
|
|
||||||
prior = &m.Inputs[i]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result, err := audio.MaterializeS3Audio(ctx, audio.S3MaterializeRequest{
|
result, err := audio.MaterializeS3Audio(ctx, audio.S3MaterializeRequest{
|
||||||
Reporter: env.Reporter, Store: env.ObjectStore, Object: obj,
|
Reporter: env.Reporter, Store: env.ObjectStore, Object: obj,
|
||||||
Bucket: strings.TrimSpace(env.Config.Pipeline.Storage.S3.Bucket), DestPath: workPath, Prior: prior,
|
Bucket: strings.TrimSpace(env.Config.Pipeline.Storage.S3.Bucket), DestPath: workPath, Prior: prior,
|
||||||
|
|||||||
@@ -359,6 +359,12 @@ func TestPrepareStageS3AudioReusesPreparedCopy(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
m.RunID = "20260515T041522Z-a1b2c3d4"
|
m.RunID = "20260515T041522Z-a1b2c3d4"
|
||||||
|
prior := findManifestInput(t, m.Inputs, "audio")
|
||||||
|
duplicate := prior
|
||||||
|
duplicate.Checksum = strings.Repeat("0", 64)
|
||||||
|
// Selection ignores other kinds and retains the first matching audio record.
|
||||||
|
m.Inputs = append([]manifest.InputRecord{{Kind: "unrelated", Path: prior.Path}}, m.Inputs...)
|
||||||
|
m.Inputs = append(m.Inputs, duplicate)
|
||||||
result, err := (prepareStage{}).Run(context.Background(), env, m)
|
result, err := (prepareStage{}).Run(context.Background(), env, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user