Query History: Remove migration (#67470)
This commit is contained in:
@@ -2,7 +2,6 @@ package queryhistory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
@@ -271,65 +270,6 @@ func (s QueryHistoryService) unstarQuery(ctx context.Context, user *user.SignedI
|
||||
return dto, nil
|
||||
}
|
||||
|
||||
// migrateQueries adds multiple queries into query history
|
||||
func (s QueryHistoryService) migrateQueries(ctx context.Context, usr *user.SignedInUser, cmd MigrateQueriesToQueryHistoryCommand) (int, int, error) {
|
||||
queryHistories := make([]*QueryHistory, 0, len(cmd.Queries))
|
||||
starredQueries := make([]*QueryHistoryStar, 0)
|
||||
|
||||
err := s.store.WithTransactionalDbSession(ctx, func(session *db.Session) error {
|
||||
for _, query := range cmd.Queries {
|
||||
uid := util.GenerateShortUID()
|
||||
queryHistories = append(queryHistories, &QueryHistory{
|
||||
OrgID: usr.OrgID,
|
||||
UID: uid,
|
||||
Queries: query.Queries,
|
||||
DatasourceUID: query.DatasourceUID,
|
||||
CreatedBy: usr.UserID,
|
||||
CreatedAt: query.CreatedAt,
|
||||
Comment: query.Comment,
|
||||
})
|
||||
|
||||
if query.Starred {
|
||||
starredQueries = append(starredQueries, &QueryHistoryStar{
|
||||
UserID: usr.UserID,
|
||||
QueryUID: uid,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
batchSize := 50
|
||||
var err error
|
||||
for i := 0; i < len(queryHistories); i += batchSize {
|
||||
j := i + batchSize
|
||||
if j > len(queryHistories) {
|
||||
j = len(queryHistories)
|
||||
}
|
||||
_, err = session.InsertMulti(queryHistories[i:j])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(starredQueries); i += batchSize {
|
||||
j := i + batchSize
|
||||
if j > len(starredQueries) {
|
||||
j = len(starredQueries)
|
||||
}
|
||||
_, err = session.InsertMulti(starredQueries[i:j])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("failed to migrate query history: %w", err)
|
||||
}
|
||||
|
||||
return len(queryHistories), len(starredQueries), nil
|
||||
}
|
||||
|
||||
func (s QueryHistoryService) deleteStaleQueries(ctx context.Context, olderThan int64) (int, error) {
|
||||
var rowsCount int64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user