UPD attachment.go: optimize checksum computation skipping when already set

This commit is contained in:
Mamut3D
2026-04-24 23:21:34 +02:00
committed by Manuel Rüger
parent 7fab1755d6
commit 68de8de09a

View File

@@ -49,6 +49,13 @@ func ResolveAttachments(
attachments []Attachment, attachments []Attachment,
) ([]Attachment, error) { ) ([]Attachment, error) {
for i := range attachments { for i := range attachments {
// Skip checksum computation if already set (e.g. by mermaid/d2 renderers
// which use the source content as the stable checksum rather than the
// rendered PNG bytes, which may be non-deterministic across environments).
if attachments[i].Checksum != "" {
continue
}
checksum, err := GetChecksum(bytes.NewReader(attachments[i].FileBytes)) checksum, err := GetChecksum(bytes.NewReader(attachments[i].FileBytes))
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to get checksum for attachment %q: %w", attachments[i].Name, err) return nil, fmt.Errorf("unable to get checksum for attachment %q: %w", attachments[i].Name, err)