agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
62 lines (57 loc) • 2.49 kB
JavaScript
/**
* @file Database connection detector for connection pool management and scalability optimization
* @description Single responsibility: Detect excessive database connections and connection management issues
*
* This detector identifies database connection patterns that can exhaust connection pools,
* cause performance degradation, and prevent application scaling. It analyzes connection
* creation patterns, pool usage, and database access efficiency to ensure optimal database
* resource utilization and prevent connection-related scalability bottlenecks.
*
* Design rationale:
* - Pattern-based detection identifies common connection management anti-patterns
* - Connection lifecycle analysis validates proper connection usage and cleanup
* - Pool exhaustion prevention through early detection of excessive connection creation
* - Context-aware analysis provides appropriate guidance for different database usage scenarios
* - Performance impact assessment helps prioritize connection optimization efforts
*
* Database connection detection scope:
* - Excessive connection creation without proper pooling or reuse
* - Connection leaks from missing connection cleanup and disposal
* - Inefficient database access patterns that waste connection resources
* - Connection pool configuration issues that limit application scalability
* - Database operation patterns that block connection availability for other requests
*/
/**
* Detects excessive database connections
* @param {string} content - File content
* @param {string} filePath - Path to the file
* @returns {Array} Array of database connection issues
*/
function detectExcessiveDBConnections(content, filePath) {
const issues = [];
const connectionPatterns = [
'new Pool(',
'createConnection(',
'connect(',
'MongoClient.connect',
'mongoose.connect'
];
connectionPatterns.forEach(pattern => {
if (content.includes(pattern)) {
issues.push({
type: 'db_connection',
severity: 'MEDIUM',
category: 'Database',
location: filePath,
pattern: pattern,
summary: `Database connection creation '${pattern}' — ensure connection pooling`,
recommendation: 'Use connection pooling and reuse connections instead of creating new ones per request',
impact: 'Excessive connections can exhaust database limits'
});
}
});
return issues;
}
module.exports = {
detectExcessiveDBConnections
};