Skip to content

Commit 702f4b5

Browse files
authored
Add index for access_token (#21908)
The `token_last_eight` field has been used in `GetAccessTokenBySHA `:
1 parent e483ec3 commit 702f4b5

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

models/auth/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type AccessToken struct {
6666
Token string `xorm:"-"`
6767
TokenHash string `xorm:"UNIQUE"` // sha256 of token
6868
TokenSalt string
69-
TokenLastEight string `xorm:"token_last_eight"`
69+
TokenLastEight string `xorm:"INDEX token_last_eight"`
7070

7171
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
7272
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ var migrations = []Migration{
441441
NewMigration("Add header_authorization_encrypted column to webhook table", v1_19.AddHeaderAuthorizationEncryptedColWebhook),
442442
// v234 -> v235
443443
NewMigration("Add package cleanup rule table", v1_19.CreatePackageCleanupRuleTable),
444+
// v235 -> v236
445+
NewMigration("Add index for access_token", v1_19.AddIndexForAccessToken),
444446
}
445447

446448
// GetCurrentDBVersion returns the current db version

models/migrations/v1_19/v235.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package v1_19 //nolint
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func AddIndexForAccessToken(x *xorm.Engine) error {
12+
type AccessToken struct {
13+
TokenLastEight string `xorm:"INDEX token_last_eight"`
14+
}
15+
16+
return x.Sync(new(AccessToken))
17+
}

0 commit comments

Comments
 (0)