recordQuery method
Implementation
void recordQuery(String connectionId, String sql, Duration executionTime) {
final metrics = QueryMetrics(
sql: sql,
executionTime: executionTime,
timestamp: DateTime.now(),
);
_queryMetrics.putIfAbsent(connectionId, () => []).add(metrics);
// Check for slow queries
if (executionTime > slowQueryThreshold) {
_alertController.add(DatabaseAlert(
type: AlertType.slowQuery,
message: 'Slow query detected',
details: {
'sql': sql,
'execution_time': executionTime.inMilliseconds,
'threshold': slowQueryThreshold.inMilliseconds,
},
));
}
if (_queryMetrics[connectionId]!.length > 1000) {
_queryMetrics[connectionId]!.removeAt(0);
}
}