fix: part of #1353, move db calls to prepared statement for checkttlstatusItem (#3976)

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
This commit is contained in:
Srikanth Iyengar 2023-11-18 10:32:19 +05:30 committed by GitHub
parent bad69abcc2
commit 36aced6d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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