From 7d6cebff146e5557c73eaf5aa4c0043c6cb32572 Mon Sep 17 00:00:00 2001 From: houchengqiu Date: Thu, 17 Aug 2023 17:38:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=9B=B8=E5=86=8C=E6=8C=82=E8=BD=BD?= =?UTF-8?q?=E5=A4=96=E8=AE=BE=E6=97=B6=EF=BC=8C=E5=90=AF=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将扫描设备路径流程放置到点击设备时执行,节省相册启动时间 Log: 相册挂载外设时,启动时间优化 Bug: https://pms.uniontech.com/bug-view-185733.html --- src/src/albumControl.cpp | 22 +++++++++++++++------- src/src/albumControl.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/src/albumControl.cpp b/src/src/albumControl.cpp index 238eff35..8db18ff3 100644 --- a/src/src/albumControl.cpp +++ b/src/src/albumControl.cpp @@ -913,9 +913,6 @@ void AlbumControl::onVfsMountChangedAdd(QExplicitlySharedDataPointer //路径存在 if (bFind) { - //挂载路径,加载文件信息 - sltLoadMountFileList(strPath); - emit sigMountsChange(); //发送新增 emit sigAddDevice(mount->getRootFile()->path()); @@ -960,6 +957,8 @@ void AlbumControl::onBlockDeviceAdded(const QString &blks) void AlbumControl::sltLoadMountFileList(const QString &path) { + QTime time; + time.start(); QString strPath = path; if (!m_PhonePicFileMap.contains(strPath)) { //获取所选文件类型过滤器 @@ -987,6 +986,8 @@ void AlbumControl::sltLoadMountFileList(const QString &path) } else { //已加载过的设备,直接发送缓存的路径 } + + qDebug() << __FUNCTION__ << QString(" load device path:%1 cost [%2]ms").arg(path).arg(time.elapsed()); } const QList > AlbumControl::getVfsMountList() @@ -2295,12 +2296,19 @@ QString AlbumControl::getDeviceName(const QString &devicePath) return m_durlAndNameMap.value(devicePath); } -QStringList AlbumControl::getDevicePicPaths(const QString &path) +QStringList AlbumControl::getDevicePicPaths(const QString &strPath) { + // 若设备路径未被扫描,先扫描出所有图片/视频文件,设备容量越大,文件越大,扫描耗时越长 + if (m_PhonePicFileMap.find(strPath) == m_PhonePicFileMap.end()) { + sltLoadMountFileList(strPath); + } + QStringList pathsList; - QStringList list = m_PhonePicFileMap.value(path); - for (QString path : list) { - pathsList << "file://" + path; + if (m_PhonePicFileMap.find(strPath) != m_PhonePicFileMap.end()) { + QStringList list = m_PhonePicFileMap.value(strPath); + for (QString path : list) { + pathsList << "file://" + path; + } } return pathsList; } diff --git a/src/src/albumControl.h b/src/src/albumControl.h index 5861f1ec..e779fb59 100644 --- a/src/src/albumControl.h +++ b/src/src/albumControl.h @@ -246,7 +246,7 @@ class AlbumControl : public QObject Q_INVOKABLE QString getDeviceName(const QString &devicePath); //获取设备的图片 - Q_INVOKABLE QStringList getDevicePicPaths(const QString &path); + Q_INVOKABLE QStringList getDevicePicPaths(const QString &strPath); //获得device路径 Q_INVOKABLE QVariantMap getDeviceAlbumInfos(const QString &devicePath, const int &filterType = 0);