configurable scan parallelism based on hdd or sdd

This commit is contained in:
2026-02-19 13:59:02 -05:00
parent 81793975b4
commit d9ebd38382
19 changed files with 1579 additions and 142 deletions
+28 -7
View File
@@ -4,8 +4,16 @@ import (
"fmt"
"io"
"os"
"time"
)
// ExtractionTiming holds sub-operation durations from a single
// ExtractAllMetadata call so callers can build per-format aggregates.
type ExtractionTiming struct {
TagExtraction time.Duration
DurationExtraction time.Duration
}
// AudioFileExtension represents a supported audio file extension.
type AudioFileExtension string
@@ -55,13 +63,16 @@ func GetTrackLengthMillis(path string) (int64, error) {
// ExtractAllMetadata opens the file once and extracts both tags and duration.
// This avoids the overhead of opening the file twice when both are needed.
// If skipDuration is true, only tags are extracted and lengthMillis is 0.
// The returned ExtractionTiming records how long each sub-operation took.
func ExtractAllMetadata(
path string,
skipDuration bool,
) (*TrackMetadata, int64, error) {
) (*TrackMetadata, int64, *ExtractionTiming, error) {
timing := &ExtractionTiming{}
f, err := os.Open(path)
if err != nil {
return nil, 0, fmt.Errorf(
return nil, 0, timing, fmt.Errorf(
"could not open file: %w", err,
)
}
@@ -69,30 +80,40 @@ func ExtractAllMetadata(
defer func() { _ = f.Close() }()
// Extract tags first (reads only headers, fast).
tagStart := time.Now()
tags, err := ExtractTagsFromReader(f)
timing.TagExtraction = time.Since(tagStart)
if err != nil {
return nil, 0, fmt.Errorf(
return nil, 0, timing, fmt.Errorf(
"could not extract tags from %s: %w", path, err,
)
}
if skipDuration {
return tags, 0, nil
return tags, 0, timing, nil
}
// Seek back to the beginning for duration extraction.
if _, err := f.Seek(0, io.SeekStart); err != nil {
return tags, 0, fmt.Errorf(
return tags, 0, timing, fmt.Errorf(
"could not seek file for duration: %w", err,
)
}
durStart := time.Now()
lengthMillis, err := getTrackDuration(f)
timing.DurationExtraction = time.Since(durStart)
if err != nil {
return tags, 0, fmt.Errorf(
return tags, 0, timing, fmt.Errorf(
"error getting duration for %s: %w", path, err,
)
}
return tags, lengthMillis, nil
return tags, lengthMillis, timing, nil
}