Skip to content

Commit d2ebd8f

Browse files
18202781743deepin-bot[bot]
authored andcommitted
feat: manage QML cache versioning proactively
Added QML cache management to handle version changes and prevent stale cache issues. The changes include: 1. Added refreshQmlCache() function to manage QML disk cache based on application version 2. Moved application version setting earlier in main() to enable cache management 3. The cache management function checks for existing cache directory and removes it if version mismatch is detected 4. Creates new cache directory with current version to ensure fresh QML compilation 5. Added QDir include for directory operations This change is necessary because QML cache can become stale when application version changes, leading to potential runtime issues. By proactively managing the cache directory based on version, we ensure that QML components are recompiled when needed. Log: Improved QML cache management to handle version changes automatically Influence: 1. Test application startup with different version strings 2. Verify QML cache directory creation and cleanup 3. Test with QML_DISK_CACHE_PATH environment variable set 4. Verify QML component loading after version change 5. Test cache persistence across application restarts 6. Monitor for any QML compilation performance changes feat: 主动管理 QML 缓存版本控制 添加了 QML 缓存管理功能以处理版本变更并防止缓存过期问题。变更包括: 1. 添加 refreshQmlCache() 函数来根据应用版本管理 QML 磁盘缓存 2. 将应用版本设置移到 main() 函数更早的位置以启用缓存管理 3. 缓存管理函数检查现有缓存目录,如果检测到版本不匹配则删除旧缓存 4. 创建带有当前版本的新缓存目录以确保 QML 重新编译 5. 添加 QDir 包含以支持目录操作 此变更是必要的,因为当应用版本变更时,QML 缓存可能变得过时,导致潜在的 运行时问题。通过基于版本主动管理缓存目录,我们确保在需要时重新编译 QML 组件。 Log: 改进 QML 缓存管理以自动处理版本变更 Influence: 1. 使用不同版本字符串测试应用启动 2. 验证 QML 缓存目录的创建和清理 3. 测试设置 QML_DISK_CACHE_PATH 环境变量的情况 4. 验证版本变更后的 QML 组件加载 5. 测试跨应用重启的缓存持久性 6. 监控 QML 编译性能变化
1 parent c96fceb commit d2ebd8f

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

src/dde-control-center/main.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <QStandardPaths>
2020
#include <QStringList>
2121
#include <QWindow>
22+
#include <QDir>
2223

2324
DGUI_USE_NAMESPACE
2425
DCORE_USE_NAMESPACE
@@ -51,6 +52,27 @@ QStringList defaultpath()
5152
return path;
5253
}
5354

55+
static void refreshQmlCache(const QString &version)
56+
{
57+
if (version.isEmpty())
58+
return;
59+
static const QByteArray envCachePath = qgetenv("QML_DISK_CACHE_PATH");
60+
61+
QString directory = envCachePath.isEmpty()
62+
? QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
63+
+ QLatin1String("/qmlcache/")
64+
: QString::fromLocal8Bit(envCachePath) + QLatin1String("/");
65+
66+
QDir dir(directory);
67+
if (dir.exists()) {
68+
if (dir.exists(version))
69+
return;
70+
const auto ret = dir.removeRecursively();
71+
qDebug() << "Remove old QML cache:" << directory << "result:" << ret;
72+
}
73+
dir.mkpath(version);
74+
}
75+
5476
int main(int argc, char *argv[])
5577
{
5678
QGuiApplication *app = new QGuiApplication(argc, argv);
@@ -60,6 +82,16 @@ int main(int argc, char *argv[])
6082

6183
app->setOrganizationName("deepin");
6284
app->setApplicationName("dde-control-center");
85+
#ifdef CVERSION
86+
QString verstr(CVERSION);
87+
if (verstr.isEmpty())
88+
verstr = "6.0";
89+
app->setApplicationVersion(verstr);
90+
#else
91+
app->setApplicationVersion("6.0");
92+
#endif
93+
94+
refreshQmlCache(app->applicationVersion());
6395

6496
// take care of command line options
6597
QCommandLineOption showOption(QStringList() << "s" << "show", "show control center(hide for default).");
@@ -129,14 +161,6 @@ int main(int argc, char *argv[])
129161
// To Fix Qt6 find icons will ignore ${GenericDataLocation}/icons/xxx
130162
QIcon::setFallbackSearchPaths(fallbacks);
131163

132-
#ifdef CVERSION
133-
QString verstr(CVERSION);
134-
if (verstr.isEmpty())
135-
verstr = "6.0";
136-
app->setApplicationVersion(verstr);
137-
#else
138-
app->setApplicationVersion("6.0");
139-
#endif
140164
app->setWindowIcon(DIconTheme::findQIcon("preferences-system"));
141165
dccV25::DccManager::installTranslator("dde-control-center");
142166
app->setApplicationDisplayName(QObject::tr("Control Center"));

0 commit comments

Comments
 (0)