Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix data conflict when prepending preloads from document meta #379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,13 @@ func (r repository) withDefaultScope(meta DocumentMeta, query Query, preload boo
}

if preload && bool(query.CascadeQuery) {
query.PreloadQuery = append(meta.preload, query.PreloadQuery...)
// Clone meta.preload to avoid data race
//
// The implementation for cloning a slice is the same as `slices.Clone` in go 1.23
// https://cs.opensource.google/go/go/+/refs/tags/go1.23.3:src/slices/slices.go;l=350
metaPreload := append(meta.preload[:0:0], meta.preload...)

query.PreloadQuery = append(metaPreload, query.PreloadQuery...)
}

return query
Expand Down
Loading