From 68de8de09a40fb8bfc325e2c5dad7537114275c0 Mon Sep 17 00:00:00 2001 From: Mamut3D <> Date: Fri, 24 Apr 2026 23:21:34 +0200 Subject: [PATCH] UPD attachment.go: optimize checksum computation skipping when already set --- attachment/attachment.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/attachment/attachment.go b/attachment/attachment.go index df25f60..516d5f6 100644 --- a/attachment/attachment.go +++ b/attachment/attachment.go @@ -49,6 +49,13 @@ func ResolveAttachments( attachments []Attachment, ) ([]Attachment, error) { 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)) if err != nil { return nil, fmt.Errorf("unable to get checksum for attachment %q: %w", attachments[i].Name, err)