speed optimizations
This commit is contained in:
@@ -19,7 +19,7 @@ func VerifyOutput(path string) error {
|
||||
|
||||
slog.Info("verifying SQL content")
|
||||
catCmd := exec.Command("zstdcat", path)
|
||||
headCmd := exec.Command("head", "-20")
|
||||
headCmd := exec.Command("head", fmt.Sprintf("-%d", verificationHeadLines))
|
||||
|
||||
pipe, err := catCmd.StdoutPipe()
|
||||
if err != nil {
|
||||
@@ -30,16 +30,23 @@ func VerifyOutput(path string) error {
|
||||
var headOut strings.Builder
|
||||
headCmd.Stdout = &headOut
|
||||
|
||||
if err := headCmd.Start(); err != nil {
|
||||
return fmt.Errorf("starting head: %w", err)
|
||||
}
|
||||
if err := catCmd.Start(); err != nil {
|
||||
return fmt.Errorf("starting zstdcat: %w", err)
|
||||
}
|
||||
if err := headCmd.Start(); err != nil {
|
||||
catCmd.Process.Kill() // Clean up if head fails to start
|
||||
return fmt.Errorf("starting head: %w", err)
|
||||
}
|
||||
|
||||
// head closes pipe early, zstdcat gets SIGPIPE - expected
|
||||
_ = headCmd.Wait()
|
||||
_ = catCmd.Wait()
|
||||
// Wait for head first (it will exit when it has enough lines)
|
||||
if err := headCmd.Wait(); err != nil {
|
||||
catCmd.Process.Kill()
|
||||
return fmt.Errorf("head command failed: %w", err)
|
||||
}
|
||||
|
||||
// Kill zstdcat since head closed the pipe (expected SIGPIPE)
|
||||
catCmd.Process.Kill()
|
||||
_ = catCmd.Wait() // Reap the process
|
||||
|
||||
content := headOut.String()
|
||||
if len(content) == 0 {
|
||||
@@ -53,9 +60,10 @@ func VerifyOutput(path string) error {
|
||||
break
|
||||
}
|
||||
}
|
||||
const verificationSampleBytes = 200
|
||||
if !hasSQLMarker {
|
||||
return fmt.Errorf("decompressed content does not look like SQL; first 200 bytes: %s",
|
||||
content[:min(200, len(content))])
|
||||
return fmt.Errorf("decompressed content does not look like SQL; first %d bytes: %s",
|
||||
verificationSampleBytes, content[:min(verificationSampleBytes, len(content))])
|
||||
}
|
||||
|
||||
slog.Info("SQL content verification passed")
|
||||
|
||||
Reference in New Issue
Block a user