mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Change queryStruct to use tx.Get instead of queryFunc
Using queryFunc meant that the performance logging was inaccurate due to the query actually being executed during the call to Scan.
This commit is contained in:
parent
39fd8a6550
commit
8e10798fc4
1 changed files with 5 additions and 6 deletions
|
|
@ -119,13 +119,12 @@ func (r *repository) queryFunc(ctx context.Context, query string, args []interfa
|
|||
return nil
|
||||
}
|
||||
|
||||
// queryStruct executes a query and scans the result into the provided struct.
|
||||
// Unlike the other query methods, this will return an error if no rows are found.
|
||||
func (r *repository) queryStruct(ctx context.Context, query string, args []interface{}, out interface{}) error {
|
||||
if err := r.queryFunc(ctx, query, args, true, func(rows *sqlx.Rows) error {
|
||||
if err := rows.StructScan(out); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
// changed from queryFunc, since it was not logging the performance correctly,
|
||||
// since the query doesn't actually execute until Scan is called
|
||||
if err := dbWrapper.Get(ctx, out, query, args...); err != nil {
|
||||
return fmt.Errorf("executing query: %s [%v]: %w", query, args, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue