MCPcopy Index your code
hub / github.com/bytebase/bytebase / createQueryHistory

Method createQueryHistory

backend/api/v1/sql_service.go:1372–1406  ·  view source on GitHub ↗
(database *store.DatabaseMessage, queryType store.QueryHistoryType, statement string, userEmail string, duration time.Duration, queryErr error)

Source from the content-addressed store, hash-verified

1370}
1371
1372func (s *SQLService) createQueryHistory(database *store.DatabaseMessage, queryType store.QueryHistoryType, statement string, userEmail string, duration time.Duration, queryErr error) {
1373 qh := &store.QueryHistoryMessage{
1374 Creator: userEmail,
1375 Project: database.ProjectID,
1376 Database: common.FormatDatabase(database.InstanceID, database.DatabaseName),
1377 Statement: statement,
1378 Type: queryType,
1379 Payload: &storepb.QueryHistoryPayload{
1380 Error: nil,
1381 Duration: durationpb.New(duration),
1382 },
1383 }
1384 if queryErr != nil {
1385 qh.Payload.Error = new(queryErr.Error())
1386 }
1387
1388 // Use a fresh context with timeout for creating query history
1389 // to avoid being affected by request cancellation
1390 historyCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
1391 defer cancel()
1392 if _, err := s.store.CreateQueryHistory(historyCtx, qh); err != nil {
1393 queryErr := ""
1394 if v := qh.Payload.Error; v != nil {
1395 queryErr = *v
1396 }
1397 slog.Error(
1398 "failed to create query history",
1399 log.BBError(err),
1400 slog.String("instance", database.InstanceID),
1401 slog.String("database", database.DatabaseName),
1402 slog.String("project", database.ProjectID),
1403 slog.String("query_error", queryErr),
1404 )
1405 }
1406}
1407
1408// SearchQueryHistories lists query histories.
1409func (s *SQLService) SearchQueryHistories(ctx context.Context, req *connect.Request[v1pb.SearchQueryHistoriesRequest]) (*connect.Response[v1pb.SearchQueryHistoriesResponse], error) {

Callers 3

AdminExecuteMethod · 0.95
QueryMethod · 0.95
ExportMethod · 0.95

Calls 6

FormatDatabaseFunction · 0.92
BBErrorFunction · 0.92
cancelFunction · 0.85
CreateQueryHistoryMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected