fix(notification): Enable WAL mode and optimize SQLite configuration …#1468
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom Mar 3, 2026
Merged
fix(notification): Enable WAL mode and optimize SQLite configuration …#1468deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
…for notification performance Configure SQLite WAL mode, NORMAL sync level and 10MB cache to improve notification processing performance, resolving blocking issues during high-frequency notification updates. Log: 启用WAL模式和优化SQLite配置,提升通知系统并发性能,解决高频通知更新时的阻塞问题。 PMS: BUG-338965 Influence: 写操作不再阻塞读操作,读不阻塞写,消除通知刷新卡顿.
deepin pr auto review这段代码主要对 SQLite 数据库连接进行了一些性能优化配置。以下是对这段代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全四个方面: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码建议// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dbaccessor.h"
// 定义常量,避免魔法数字
static const int kCacheSizeInKB = -10240; // -10240KB = -10MB
bool DBAccessor::open(const QString &dataPath)
{
// ... 前面的检查代码保持不变 ...
if (!QSqlDatabase::contains(m_connectionName)) {
// ... 数据库添加逻辑 ...
}
m_connection = QSqlDatabase::database(m_connectionName);
// === Performance Optimization: WAL Mode and Sync Level ===
QSqlQuery query(m_connection);
// WAL mode: Reads don't block writes, writes don't block reads
// 这是一个关键设置,失败应记录严重错误
if (!query.exec("PRAGMA journal_mode=WAL")) {
qCritical(notifyLog) << "Failed to set WAL mode:" << query.lastError().text();
// 根据业务需求决定是否返回 false
// return false;
}
// Lower sync level: NORMAL balances performance and safety.
// 崩溃时可能丢失最近的事务,但能显著提升性能。
if (!query.exec("PRAGMA synchronous=NORMAL")) {
qWarning(notifyLog) << "Failed to set synchronous:" << query.lastError().text();
}
// Increase cache size: 10MB for better performance
if (!query.exec(QString("PRAGMA cache_size=%1").arg(kCacheSizeInKB))) {
qWarning(notifyLog) << "Failed to set cache_size:" << query.lastError().text();
}
// 移除 PRAGMA optimize,避免每次打开连接时的性能开销
// 移除 PRAGMA read_uncommitted,因为 WAL 模式下读写已不阻塞,且脏读不安全
return true;
}总结修改点:
|
18202781743
approved these changes
Mar 3, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, re2zero The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/merge |
|
This pr cannot be merged! (status: unstable) |
Contributor
Author
|
/forcemerge |
|
This pr force merged! (status: unstable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…for notification performance
Configure SQLite WAL mode, NORMAL sync level and 10MB cache to improve notification processing performance, resolving blocking issues during high-frequency notification updates.
Log: 启用WAL模式和优化SQLite配置,提升通知系统并发性能,解决高频通知更新时的阻塞问题。
PMS: BUG-338965
Influence: 写操作不再阻塞读操作,读不阻塞写,消除通知刷新卡顿.