From 36aced6d1ad30d6ce26ed3aa0eba2c626d0b6b03 Mon Sep 17 00:00:00 2001 From: Srikanth Iyengar Date: Sat, 18 Nov 2023 10:32:19 +0530 Subject: [PATCH] fix: part of #1353, move db calls to prepared statement for checkttlstatusItem (#3976) Co-authored-by: Srikanth Chekuri --- pkg/query-service/app/clickhouseReader/reader.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go index 8816179da2..8b42c9265a 100644 --- a/pkg/query-service/app/clickhouseReader/reader.go +++ b/pkg/query-service/app/clickhouseReader/reader.go @@ -2456,11 +2456,18 @@ func (r *ClickHouseReader) deleteTtlTransactions(ctx context.Context, numberOfTr func (r *ClickHouseReader) checkTTLStatusItem(ctx context.Context, tableName string) (model.TTLStatusItem, *model.ApiError) { statusItem := []model.TTLStatusItem{} - query := fmt.Sprintf("SELECT id, status, ttl, cold_storage_ttl FROM ttl_status WHERE table_name = '%s' ORDER BY created_at DESC", tableName) + query := `SELECT id, status, ttl, cold_storage_ttl FROM ttl_status WHERE table_name = ? ORDER BY created_at DESC` - err := r.localDB.Select(&statusItem, query) + zap.S().Info(query, tableName) - zap.S().Info(query) + stmt, err := r.localDB.Preparex(query) + + if err != nil { + zap.S().Debug("Error preparing query for checkTTLStatusItem: ", err) + return model.TTLStatusItem{}, &model.ApiError{Typ: model.ErrorInternal, Err: err} + } + + err = stmt.Select(&statusItem, tableName) if len(statusItem) == 0 { return model.TTLStatusItem{}, nil