* @brief Closes the database, removes the connection, clears caches. */
| 113 | * @brief Closes the database, removes the connection, clears caches. |
| 114 | */ |
| 115 | void Sessions::DatabaseWorker::closeDatabase() |
| 116 | { |
| 117 | m_cancelRequested.store(true, std::memory_order_release); |
| 118 | |
| 119 | m_sessionList.clear(); |
| 120 | m_tagList.clear(); |
| 121 | m_passwordHash.clear(); |
| 122 | m_locked = false; |
| 123 | |
| 124 | if (QCoreApplication::instance()) { |
| 125 | if (m_db.isOpen()) { |
| 126 | QSqlQuery checkpoint(m_db); |
| 127 | checkpoint.exec("PRAGMA wal_checkpoint(RESTART)"); |
| 128 | m_db.close(); |
| 129 | } |
| 130 | |
| 131 | const QString conn = m_connectionName; |
| 132 | m_db = QSqlDatabase(); |
| 133 | if (!conn.isEmpty()) |
| 134 | QSqlDatabase::removeDatabase(conn); |
| 135 | } |
| 136 | |
| 137 | m_filePath.clear(); |
| 138 | m_connectionName.clear(); |
| 139 | m_cancelRequested.store(false, std::memory_order_release); |
| 140 | |
| 141 | Q_EMIT closed(); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @brief Re-runs every internal cache fetch and ships the results back. |