Skip to content

Commit 5f65c1a

Browse files
committed
feat: fandom doesn't need queries by nid, to speed up the queries skip nid where clauses, this will need to be revewed during the next kratos upgrade, SPLAT-930
1 parent ab70aaf commit 5f65c1a

8 files changed

Lines changed: 9 additions & 16 deletions

persistence/sql/persister_continuity.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ func (p *Persister) DeleteExpiredContinuitySessions(ctx context.Context, expires
7676
defer otelx.End(span, &err)
7777
//#nosec G201 -- TableName is static
7878
err = p.GetConnection(ctx).RawQuery(fmt.Sprintf(
79-
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? and nid = ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
79+
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
8080
new(continuity.Container).TableName(ctx),
8181
new(continuity.Container).TableName(ctx),
8282
limit,
8383
),
8484
expiresAt,
85-
p.NetworkID(ctx),
8685
).Exec()
8786
if err != nil {
8887
return sqlcon.HandleError(err)

persistence/sql/persister_login.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ func (p *Persister) DeleteExpiredLoginFlows(ctx context.Context, expiresAt time.
7373
defer otelx.End(span, &err)
7474
//#nosec G201 -- TableName is static
7575
err = p.GetConnection(ctx).RawQuery(fmt.Sprintf(
76-
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? and nid = ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
76+
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
7777
new(login.Flow).TableName(ctx),
7878
new(login.Flow).TableName(ctx),
7979
limit,
8080
),
8181
expiresAt,
82-
p.NetworkID(ctx),
8382
).Exec()
8483
if err != nil {
8584
return sqlcon.HandleError(err)

persistence/sql/persister_recovery.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ func (p *Persister) DeleteExpiredRecoveryFlows(ctx context.Context, expiresAt ti
124124
defer otelx.End(span, &err)
125125
//#nosec G201 -- TableName is static
126126
err = p.GetConnection(ctx).RawQuery(fmt.Sprintf(
127-
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? and nid = ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
127+
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
128128
new(recovery.Flow).TableName(ctx),
129129
new(recovery.Flow).TableName(ctx),
130130
limit,
131131
),
132132
expiresAt,
133-
p.NetworkID(ctx),
134133
).Exec()
135134
if err != nil {
136135
return sqlcon.HandleError(err)

persistence/sql/persister_registration.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ func (p *Persister) DeleteExpiredRegistrationFlows(ctx context.Context, expiresA
5454
defer otelx.End(span, &err)
5555
//#nosec G201 -- TableName is static
5656
err = p.GetConnection(ctx).RawQuery(fmt.Sprintf(
57-
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? and nid = ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
57+
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
5858
new(registration.Flow).TableName(ctx),
5959
new(registration.Flow).TableName(ctx),
6060
limit,
6161
),
6262
expiresAt,
63-
p.NetworkID(ctx),
6463
).Exec()
6564
if err != nil {
6665
return sqlcon.HandleError(err)

persistence/sql/persister_session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,10 @@ func (p *Persister) DeleteExpiredSessions(ctx context.Context, expiresAt time.Ti
509509

510510
//#nosec G201 -- TableName is static
511511
if err = p.GetConnection(ctx).RawQuery(fmt.Sprintf(
512-
"SELECT id FROM %s WHERE (expires_at <= ? OR active = false) AND nid = ? ORDER BY expires_at ASC LIMIT %d",
512+
"SELECT id FROM %s WHERE expires_at <= ? OR active = false ORDER BY expires_at ASC LIMIT %d",
513513
new(session.Session).TableName(ctx),
514514
limit,
515-
), expiresAt, p.NetworkID(ctx)).All(&rows); err != nil {
515+
), expiresAt).All(&rows); err != nil {
516516
return sqlcon.HandleError(err)
517517
}
518518

persistence/sql/persister_sessiontokenexchanger.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,12 @@ func (p *Persister) DeleteExpiredExchangers(ctx context.Context, at time.Time, l
114114

115115
//#nosec G201 -- TableName is static
116116
err := conn.RawQuery(fmt.Sprintf(
117-
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE created_at <= ? and nid = ? ORDER BY created_at ASC LIMIT %d ) AS s )",
117+
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE created_at <= ? ORDER BY created_at ASC LIMIT %d ) AS s )",
118118
conn.Dialect.Quote(new(sessiontokenexchange.Exchanger).TableName()),
119119
conn.Dialect.Quote(new(sessiontokenexchange.Exchanger).TableName()),
120120
limit,
121121
),
122122
expiredAfter,
123-
p.NetworkID(ctx),
124123
).Exec()
125124

126125
return sqlcon.HandleError(err)

persistence/sql/persister_settings.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ func (p *Persister) DeleteExpiredSettingsFlows(ctx context.Context, expiresAt ti
6464
defer otelx.End(span, &err)
6565
//#nosec G201 -- TableName is static
6666
err = p.GetConnection(ctx).RawQuery(fmt.Sprintf(
67-
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? and nid = ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
67+
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
6868
new(settings.Flow).TableName(ctx),
6969
new(settings.Flow).TableName(ctx),
7070
limit,
7171
),
7272
expiresAt,
73-
p.NetworkID(ctx),
7473
).Exec()
7574
if err != nil {
7675
return sqlcon.HandleError(err)

persistence/sql/persister_verification.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ func (p *Persister) DeleteExpiredVerificationFlows(ctx context.Context, expiresA
124124
defer otelx.End(span, &err)
125125
//#nosec G201 -- TableName is static
126126
err = p.GetConnection(ctx).RawQuery(fmt.Sprintf(
127-
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? and nid = ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
127+
"DELETE FROM %s WHERE id in (SELECT id FROM (SELECT id FROM %s c WHERE expires_at <= ? ORDER BY expires_at ASC LIMIT %d ) AS s )",
128128
new(verification.Flow).TableName(ctx),
129129
new(verification.Flow).TableName(ctx),
130130
limit,
131131
),
132132
expiresAt,
133-
p.NetworkID(ctx),
134133
).Exec()
135134
if err != nil {
136135
return sqlcon.HandleError(err)

0 commit comments

Comments
 (0)