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: provide index hint in QueryForCredentials #3329

Merged
merged 4 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,6 @@ func (p *Config) CORS(ctx context.Context, iface string) (cors.Options, bool) {
}
}

func (p *Config) SetTracer(ctx context.Context, t *otelx.Tracer) {
p.GetProvider(ctx).SetTracer(ctx, t)
}

func (p *Config) cors(ctx context.Context, prefix string) (cors.Options, bool) {
return p.GetProvider(ctx).CORS(prefix, cors.Options{
AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"},
Expand Down
1 change: 0 additions & 1 deletion driver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ func NewWithoutInit(ctx context.Context, stdOutOrErr io.Writer, sl *servicelocat
return nil, err
}

c.SetTracer(ctx, r.Tracer(ctx))
return r, nil
}
19 changes: 14 additions & 5 deletions persistence/sql/identity/persister_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ func (p *IdentityPersister) HydrateIdentityAssociations(ctx context.Context, i *
// https://github.com/gobuffalo/pop/issues/723
con := con.WithContext(ctx)
creds, err := QueryForCredentials(con,
"identity_credential_identifiers.identity_credential_id = identity_credentials.id AND identity_credential_identifiers.nid = identity_credentials.nid",
Where{"(identity_credentials.identity_id = ? AND identity_credentials.nid = ?)", []interface{}{i.ID, nid}})
if err != nil {
return err
Expand Down Expand Up @@ -582,7 +581,18 @@ type Where struct {

// QueryForCredentials queries for identity credentials with custom WHERE
// clauses, returning the results resolved by the owning identity's UUID.
func QueryForCredentials(con *pop.Connection, joinOn string, where ...Where) (map[uuid.UUID](map[identity.CredentialsType]identity.Credentials), error) {
func QueryForCredentials(con *pop.Connection, where ...Where) (map[uuid.UUID](map[identity.CredentialsType]identity.Credentials), error) {
ici := "identity_credential_identifiers"
switch con.Dialect.Name() {
case "cockroach":
ici += "@identity_credential_identifiers_nid_identity_credential_id_idx"
Fixed Show fixed Hide fixed
case "sqlite3":
ici += " INDEXED BY identity_credential_identifiers_nid_identity_credential_id_idx"
Fixed Show fixed Hide fixed
case "mysql":
ici += " USE INDEX(identity_credential_identifiers_nid_identity_credential_id_idx)"
Fixed Show fixed Hide fixed
default:
// good luck 🤷‍♂️
}
q := con.Select(
"identity_credentials.id cred_id",
"identity_credentials.identity_id identity_id",
Expand All @@ -598,8 +608,8 @@ func QueryForCredentials(con *pop.Connection, joinOn string, where ...Where) (ma
"identity_credential_types ict",
"(identity_credentials.identity_credential_type_id = ict.id)",
).LeftJoin(
"identity_credential_identifiers",
joinOn,
ici,
"identity_credential_identifiers.identity_credential_id = identity_credentials.id AND identity_credential_identifiers.nid = identity_credentials.nid",
)
for _, w := range where {
q = q.Where("("+w.Condition+")", w.Args...)
Expand Down Expand Up @@ -705,7 +715,6 @@ func (p *IdentityPersister) ListIdentities(ctx context.Context, params identity.
ids = append(ids, is[k].ID)
}
creds, err := QueryForCredentials(con,
"identity_credential_identifiers.identity_credential_id = identity_credentials.id AND identity_credential_identifiers.nid = identity_credentials.nid",
Where{"identity_credentials.nid = ?", []interface{}{nid}},
Where{"identity_credentials.identity_id IN (?)", ids})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- nothing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- nothing: needed for foreign key anyways
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX identity_credential_identifiers_nid_identity_credential_id_idx ON identity_credential_identifiers (identity_credential_id, nid);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- index already exists