mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
Don't depend on last inserted id to get the id for the new software (#4298)
* Don't depend on last inserted id to get the id for the new software * Correct typo
This commit is contained in:
parent
c641e39ef4
commit
6d582cffa0
1
changes/issue-4082-host-software-0
Normal file
1
changes/issue-4082-host-software-0
Normal file
@ -0,0 +1 @@
|
||||
* Don't depend on lastInsertedId to gather the id of the new software
|
@ -186,7 +186,7 @@ func getOrGenerateSoftwareIdDB(ctx context.Context, tx sqlx.ExtContext, s fleet.
|
||||
return uint(existingId[0]), nil
|
||||
}
|
||||
|
||||
result, err := tx.ExecContext(ctx,
|
||||
_, err := tx.ExecContext(ctx,
|
||||
"INSERT INTO software "+
|
||||
"(name, version, source, `release`, vendor, arch, bundle_identifier) "+
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?) "+
|
||||
@ -196,11 +196,9 @@ func getOrGenerateSoftwareIdDB(ctx context.Context, tx sqlx.ExtContext, s fleet.
|
||||
if err != nil {
|
||||
return 0, ctxerr.Wrap(ctx, err, "insert software")
|
||||
}
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, ctxerr.Wrap(ctx, err, "last id from software")
|
||||
}
|
||||
return uint(id), nil
|
||||
// LastInsertId sometimes returns 0 as it's dependent on connections and how mysql is configured
|
||||
// doing the select recursively is a bit slower, but most times, we won't end up in this situation
|
||||
return getOrGenerateSoftwareIdDB(ctx, tx, s)
|
||||
}
|
||||
|
||||
func insertNewInstalledHostSoftwareDB(
|
||||
|
Loading…
Reference in New Issue
Block a user