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

Make TryInsert functions within the packages module use INSERT ... ON CONFLICT #21063

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7f4e851
Make TryInsert functions within the packages module try to insert first
zeripath Sep 4, 2022
b29ab42
partial still broken
zeripath Sep 6, 2022
470064c
more
zeripath Sep 6, 2022
9c83ab8
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath Sep 7, 2022
bf94b55
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath Sep 7, 2022
8d3864a
ensure that timestamps are also set
zeripath Sep 7, 2022
71522ea
oops lets try to get the mysql syntax right
zeripath Sep 7, 2022
7843fe9
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath Feb 2, 2023
abcf334
attempt to fix mysql/mssql
zeripath Feb 2, 2023
430f964
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath Feb 6, 2023
5dff21a
fix insert on conflict for sqlite
zeripath Feb 7, 2023
f934a98
fix unit-test
zeripath Feb 7, 2023
b3db6da
attempt to fix postgres
zeripath Feb 7, 2023
5bc4924
placate lint
zeripath Feb 7, 2023
8f7987c
fix mssql?
zeripath Feb 7, 2023
fc5d9aa
hopefully fix psql
zeripath Feb 7, 2023
7ec881f
get more info mssql
zeripath Feb 7, 2023
d8aa794
perhaps inserted should be INSERTED?
zeripath Feb 7, 2023
3f39045
fix mssql bug
zeripath Feb 7, 2023
15855df
add comments and slight restructure
zeripath Feb 7, 2023
38d540b
slight adjustments
zeripath Feb 7, 2023
a941cba
placate the linter
zeripath Feb 7, 2023
5ef7902
as per wxiaoguang
zeripath Feb 7, 2023
04efbf9
more comments
zeripath Feb 7, 2023
2283b23
missed setting sql
zeripath Feb 7, 2023
a282e66
add testcases
zeripath Feb 7, 2023
62b1e20
fix fmt
zeripath Feb 7, 2023
f1222e8
slight bug in mysql
zeripath Feb 7, 2023
25abc72
as per wxiaoguang
zeripath Feb 8, 2023
028b5a6
split functions out and just use ignore
zeripath Feb 8, 2023
1c17006
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath Feb 8, 2023
ac6862a
remove unnecessary mutex
zeripath Feb 9, 2023
dc4638c
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath Feb 9, 2023
ecd3eea
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath Mar 12, 2023
bf18cf8
add a few comments to test;
zeripath Mar 12, 2023
1a6f5df
fix broken merge
zeripath Mar 12, 2023
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
13 changes: 5 additions & 8 deletions models/packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,11 @@ func TryInsertPackage(ctx context.Context, p *Package) (*Package, error) {
LowerName: p.LowerName,
}

has, err := e.Get(key)
if err != nil {
return nil, err
}
if has {
return key, ErrDuplicatePackage
}
if _, err = e.Insert(p); err != nil {
if _, err := e.Insert(p); err != nil {
// Try to get the key again
if has, _ := e.Get(key); has {
return key, ErrDuplicatePackage
}
return nil, err
}
return p, nil
Expand Down
12 changes: 4 additions & 8 deletions models/packages/package_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,10 @@ func TryInsertFile(ctx context.Context, pf *PackageFile) (*PackageFile, error) {
CompositeKey: pf.CompositeKey,
}

has, err := e.Get(key)
if err != nil {
return nil, err
}
if has {
return pf, ErrDuplicatePackageFile
}
if _, err = e.Insert(pf); err != nil {
if _, err := e.Insert(pf); err != nil {
if has, _ := e.Get(key); has {
return pf, ErrDuplicatePackageFile
zeripath marked this conversation as resolved.
Show resolved Hide resolved
}
return nil, err
}
return pf, nil
Expand Down
12 changes: 4 additions & 8 deletions models/packages/package_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ func GetOrInsertVersion(ctx context.Context, pv *PackageVersion) (*PackageVersio
LowerVersion: pv.LowerVersion,
}

has, err := e.Get(key)
if err != nil {
return nil, err
}
if has {
return key, ErrDuplicatePackageVersion
}
if _, err = e.Insert(pv); err != nil {
if _, err := e.Insert(pv); err != nil {
if has, _ := e.Get(key); has {
return key, ErrDuplicatePackageVersion
}
return nil, err
}
return pv, nil
Expand Down