speed optimizations

This commit is contained in:
2026-02-12 13:01:52 -08:00
parent 2d46dc70a9
commit cf79e008b5
8 changed files with 301 additions and 79 deletions
+17 -9
View File
@@ -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")