Skip to content

Commit

Permalink
fix: add index on requested_at for refresh tokens and use it in janit…
Browse files Browse the repository at this point in the history
…or (#3516)

Co-authored-by: Henning Perl <henning.perl@ory.sh>
  • Loading branch information
sgal and hperl committed May 24, 2023
1 parent eddf7f3 commit 5b8e712
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX hydra_oauth2_refresh_requested_at_idx;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX hydra_oauth2_refresh_requested_at_idx ON hydra_oauth2_refresh (nid, requested_at);
2 changes: 1 addition & 1 deletion persistence/sql/persister_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (p *Persister) flushInactiveTokens(ctx context.Context, notAfter time.Time,
// The outer SELECT is necessary because our version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
deletedRecords, err = p.Connection(ctx).RawQuery(
fmt.Sprintf(`DELETE FROM %s WHERE signature in (
SELECT signature FROM (SELECT signature FROM %s hoa WHERE requested_at < ? and nid = ? ORDER BY signature LIMIT %d ) as s
SELECT signature FROM (SELECT signature FROM %s hoa WHERE requested_at < ? and nid = ? ORDER BY requested_at LIMIT %d ) as s
)`, OAuth2RequestSQL{Table: table}.TableName(), OAuth2RequestSQL{Table: table}.TableName(), d),
notAfter,
p.NetworkID(ctx),
Expand Down

0 comments on commit 5b8e712

Please sign in to comment.