mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-31 11:26:48 +00:00
refactor: only reset a database table when the table's data was changed (#37573)
Reduce CI time Saves about 3 minutes for each test suit test-unit: 13min -> 10min (-race) test-pgsql: 24min -> 20min (-race) test-mysql: 15min -> 12min test-mssql: 16min -> 12min --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
This commit is contained in:
@@ -17,12 +17,15 @@ import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
type engineContextKeyType struct{}
|
||||
type contextKey struct{ key string }
|
||||
|
||||
var engineContextKey = engineContextKeyType{}
|
||||
var (
|
||||
contextKeyEngine = contextKey{"engine"}
|
||||
ContextKeyTestFixtures = contextKey{"test-fixtures"}
|
||||
)
|
||||
|
||||
func withContextEngine(ctx context.Context, e Engine) context.Context {
|
||||
return context.WithValue(ctx, engineContextKey, e)
|
||||
return context.WithValue(ctx, contextKeyEngine, e)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -68,7 +71,7 @@ func contextSafetyCheck(e Engine) {
|
||||
|
||||
// GetEngine gets an existing db Engine/Statement or creates a new Session
|
||||
func GetEngine(ctx context.Context) Engine {
|
||||
if engine, ok := ctx.Value(engineContextKey).(Engine); ok {
|
||||
if engine, ok := ctx.Value(contextKeyEngine).(Engine); ok {
|
||||
// if reusing the existing session, need to do "contextSafetyCheck" because the Iterate creates a "autoResetStatement=false" session
|
||||
contextSafetyCheck(engine)
|
||||
return engine
|
||||
@@ -309,7 +312,7 @@ func InTransaction(ctx context.Context) bool {
|
||||
}
|
||||
|
||||
func getTransactionSession(ctx context.Context) *xorm.Session {
|
||||
e, _ := ctx.Value(engineContextKey).(Engine)
|
||||
e, _ := ctx.Value(contextKeyEngine).(Engine)
|
||||
if sess, ok := e.(*xorm.Session); ok && sess.IsInTx() {
|
||||
return sess
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user