Frontend Asset Optimization#7
Conversation
Codoki PR ReviewSummary: Add RWMutex around cache, prevent data races Next Steps:
Key Feedback (click to expand)
Confidence: 4/5 — Looks good; minor fixes (2 medium) Sequence DiagramsequenceDiagram
participant Caller
participant WebAssets
participant CDN
participant FS
Caller->>WebAssets: GetWebAssets(ctx, cfg, license)
alt cache hit (non-dev)
WebAssets-->>Caller: return cached EntryPointAssets
else cache miss or dev
opt try CDN
WebAssets->>CDN: GET assets-manifest.json
CDN-->>WebAssets: manifest body
WebAssets->>WebAssets: readWebAssets(body)
end
alt result == nil
WebAssets->>FS: read assets-manifest.json
FS-->>WebAssets: manifest body
WebAssets->>WebAssets: readWebAssets(body)
end
WebAssets-->>Caller: EntryPointAssets
end
React with 👍 or 👎 if you found this review useful. |
| if cfg.Env != setting.Dev && ret != nil { | ||
| return ret, nil | ||
| } | ||
| entryPointAssetsCacheMu.Lock() |
There was a problem hiding this comment.
🔷 Medium: Add a second check after acquiring the write lock to avoid redundant manifest loading under concurrent calls; the current flow can perform the entire I/O twice (first goroutine computes, second acquires the lock afterward and computes again).
suggestion
if cfg.Env != setting.Dev && entryPointAssetsCache != nil {
entryPointAssetsCacheMu.Unlock()
return entryPointAssetsCache, nil
}
defer entryPointAssetsCacheMu.Unlock()
Mirrors ai-code-review-evaluation#8 for like-for-like benchmarking.
asset-loading-baselineasset-loading-optimizedOriginal PR excerpt: