mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-06 19:08:57 +09:00
ac49dbe1a2
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v1_27
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.dev/modelmigration/base"
|
|
|
|
"xorm.io/xorm/schemas"
|
|
)
|
|
|
|
// AddCreatedUnixToActionUserIsDeletedIndex extends the c_u composite index on
|
|
// the action table to include created_unix, enabling efficient ORDER BY on the
|
|
// dashboard feed query without a full sort of all matching rows.
|
|
func AddCreatedUnixToActionUserIsDeletedIndex(ctx context.Context, x base.EngineMigration) error {
|
|
// xorm Sync cannot reliably update an index when another index already
|
|
// covers the same columns in a different order (Equal() is order-insensitive).
|
|
// Drop the old c_u index explicitly, then recreate it with the new column set.
|
|
indexes, err := x.Dialect().GetIndexes(x.DB(), ctx, "action")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, idx := range indexes {
|
|
if idx.Name == "c_u" {
|
|
if _, err := x.Exec(x.Dialect().DropIndexSQL("action", idx)); err != nil {
|
|
return err
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
newIndex := schemas.NewIndex("c_u", schemas.IndexType)
|
|
newIndex.AddColumn("user_id", "is_deleted", "created_unix")
|
|
if _, err := x.Exec(x.Dialect().CreateIndexSQL("action", newIndex)); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|