mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:31:43 +00:00
Settings: make DB calls sequentially (#53803)
We're getting a [concurrent transaction error](https://sourcegraph.sentry.io/issues/4263654659/?project=6583153&referrer=slack) from settings because somewhere we're passing a transaction as the `database.DB` then using it concurrently in this method. This updates the DB calls to run sequentially. This comes with a perf penalty, but I'd prefer a small perf impact to erroring/crashing/silently doing the wrong thing. As a followup, I will add a DB method that allows you to request settings for multiple subjects at once. That might not come until after 5.1 though, so I'd at least like to get this merged and backported.
This commit is contained in:
parent
56fb2d62c3
commit
640a338cf4
1
internal/settings/BUILD.bazel
generated
1
internal/settings/BUILD.bazel
generated
@ -14,7 +14,6 @@ go_library(
|
||||
"//internal/trace",
|
||||
"//lib/errors",
|
||||
"//schema",
|
||||
"@com_github_sourcegraph_conc//iter",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
"github.com/sourcegraph/conc/iter"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
@ -84,9 +83,13 @@ func (s *service) ForSubject(ctx context.Context, subject api.SettingsSubject) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allSettings, err := iter.MapErr(subjects, func(subject *api.SettingsSubject) (*schema.Settings, error) {
|
||||
return latest(ctx, s.db, *subject)
|
||||
})
|
||||
allSettings := make([]*schema.Settings, len(subjects))
|
||||
for i, subject := range subjects {
|
||||
allSettings[i], err = latest(ctx, s.db, subject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return mergeSettings(allSettings...), nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user