From 8ea507c001247652ae317e6c538b10f4dbf97077 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 23 Nov 2022 12:06:30 +0800 Subject: [PATCH 1/2] chore: add index on token_last_eight --- models/auth/token.go | 2 +- models/migrations/migrations.go | 2 ++ models/migrations/v1_19/v235.go | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 models/migrations/v1_19/v235.go diff --git a/models/auth/token.go b/models/auth/token.go index 17c07531f85a..9902b80b7826 100644 --- a/models/auth/token.go +++ b/models/auth/token.go @@ -66,7 +66,7 @@ type AccessToken struct { Token string `xorm:"-"` TokenHash string `xorm:"UNIQUE"` // sha256 of token TokenSalt string - TokenLastEight string `xorm:"token_last_eight"` + TokenLastEight string `xorm:"INDEX token_last_eight"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index c48fc8d9a8a9..a48c837e8b25 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -441,6 +441,8 @@ var migrations = []Migration{ NewMigration("Add header_authorization_encrypted column to webhook table", v1_19.AddHeaderAuthorizationEncryptedColWebhook), // v234 -> v235 NewMigration("Add package cleanup rule table", v1_19.CreatePackageCleanupRuleTable), + // v235 -> v236 + NewMigration("Add index for access_token", v1_19.AddIndexForAccessToken), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_19/v235.go b/models/migrations/v1_19/v235.go new file mode 100644 index 000000000000..b43ee32a56e1 --- /dev/null +++ b/models/migrations/v1_19/v235.go @@ -0,0 +1,17 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1_19 //nolint + +import ( + "xorm.io/xorm" +) + +func AddIndexForAccessToken(x *xorm.Engine) error { + type AccessToken struct { + TokenLastEight string `xorm:"INDEX token_last_eight"` + } + + return x.Sync(new(AccessToken)) +} From 0f368868a88f6bfacce8c77ba1d9474398735cd5 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 23 Nov 2022 13:01:22 +0800 Subject: [PATCH 2/2] chore: retrigger CI