Skip to content

Commit

Permalink
docs: add comments to explain why we use order by requested_at
Browse files Browse the repository at this point in the history
  • Loading branch information
arnolf authored and arnolf committed Jun 3, 2022
1 parent 53a40ce commit 85962db
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions persistence/sql/persister_consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func (p *Persister) FlushInactiveLoginConsentRequests(ctx context.Context, notAf
}

consent_challenges := []string{}
// Order by requested_at field to avoid full scan and use requested_at index
queryFormat := `
SELECT %[1]s.challenge
FROM %[1]s
Expand Down
1 change: 1 addition & 0 deletions persistence/sql/persister_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func (p *Persister) flushInactiveTokens(ctx context.Context, notAfter time.Time,
signatures := []string{}

// Select tokens' signatures with limit
// Order by requested_at field to avoid full scan and use requested_at index
q := p.Connection(ctx).RawQuery(
fmt.Sprintf("SELECT signature FROM %s WHERE requested_at < ? ORDER BY requested_at LIMIT %d",
OAuth2RequestSQL{Table: table}.TableName(), limit),
Expand Down

0 comments on commit 85962db

Please sign in to comment.