Ticket #5482: purge_connections.patch
File purge_connections.patch, 1.8 KB (added by , 16 years ago) |
---|
-
libs/libmyth/mythdbcon.h
61 61 62 62 MSqlDatabase *m_schedCon; 63 63 MSqlDatabase *m_DDCon; 64 65 void purgeConnections(void); 64 66 }; 65 67 66 68 /// \brief MSqlDatabase Info, used by MSqlQuery. Do not use directly. -
libs/libmyth/mythdbcon.cpp
203 203 204 204 MSqlDatabase *db; 205 205 206 // If there exists too many unused/old DB-connections, close them. 207 purgeConnections(); 208 206 209 if (m_pool.isEmpty()) 207 210 { 208 211 db = new MSqlDatabase("DBManager" + QString::number(m_connID++)); 209 212 VERBOSE(VB_IMPORTANT, QString("New DB connection, total: %1").arg(m_connID)); 210 213 } 211 214 else 215 { 216 // Use the list as FIFO in order to rotate the used connections. 212 217 db = m_pool.takeLast(); 218 } 213 219 214 220 m_lock.unlock(); 215 221 … … 224 230 225 231 if (db) 226 232 { 227 m_pool.append(db); 233 db->m_lastDBKick = QDateTime::currentDateTime(); 234 m_pool.prepend(db); 228 235 } 229 236 230 237 m_lock.unlock(); 231 238 m_sem->release(); 232 239 } 233 240 241 void MDBManager::purgeConnections() 242 { 243 // 244 // Must be called with a valid MDBManager-lock! 245 // 246 int i; 247 QDateTime now; 248 249 now=QDateTime::currentDateTime(); 250 for(i = 0; i < m_pool.size(); ++i) 251 { 252 if (m_pool[i]->m_lastDBKick.secsTo(now) > 3600) 253 { 254 // This connection has 255 // not been used in the past hour. 256 --m_connID; 257 delete m_pool[i]; 258 continue; 259 } 260 } 261 return; 262 } 263 264 234 265 MSqlDatabase *MDBManager::getSchedCon() 235 266 { 236 267 if (!m_schedCon)