Commit 887b986c authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Massive speedup on project load (at least when working on nfs filesystem)

Related to #1266
parent e8f27dac
Pipeline #118353 passed with stage
in 5 minutes and 2 seconds
......@@ -17,14 +17,44 @@ FileWatcher::FileWatcher(QObject *parent)
connect(KDirWatch::self(), &KDirWatch::deleted, this, &FileWatcher::slotUrlMissing);
connect(KDirWatch::self(), &KDirWatch::created, this, &FileWatcher::slotUrlAdded);
connect(&m_modifiedTimer, &QTimer::timeout, this, &FileWatcher::slotProcessModifiedUrls);
m_queueTimer.setInterval(300);
m_queueTimer.setSingleShot(true);
connect(&m_queueTimer, &QTimer::timeout, this, &FileWatcher::slotProcessQueue);
}
void FileWatcher::slotProcessQueue()
{
if (m_pendingUrls.size() == 0) {
return;
}
auto iter = m_pendingUrls.begin();
doAddFile(iter->first, iter->second);
m_pendingUrls.erase(iter->first);
if (m_pendingUrls.size() > 0 && !m_queueTimer.isActive()) {
m_queueTimer.start();
}
}
void FileWatcher::addFile(const QString &binId, const QString &url)
{
if (m_occurences.count(url) > 0) {
// Already queued
return;
}
m_pendingUrls[binId] = url;
if (!m_queueTimer.isActive()) {
m_queueTimer.start();
}
}
void FileWatcher::doAddFile(const QString &binId, const QString &url)
{
if (url.isEmpty()) {
return;
}
if (m_occurences.count(url) == 0) {
//QtConcurrent::run([=] { KDirWatch::self()->addFile(url); });
KDirWatch::self()->addFile(url);
}
m_occurences[url].insert(binId);
......
......@@ -22,7 +22,7 @@ class FileWatcher : public QObject
public:
// Constructor
explicit FileWatcher(QObject *parent = nullptr);
// Add a file to the list of watched items
// Add a file to the queue for watched items
void addFile(const QString &binId, const QString &url);
// Remove a binId from the list of watched items
void removeFile(const QString &binId);
......@@ -44,6 +44,7 @@ private slots:
void slotUrlMissing(const QString &path);
void slotUrlAdded(const QString &path);
void slotProcessModifiedUrls();
void slotProcessQueue();
private:
// A list with urls as keys, and the corresponding clip ids as value
......@@ -53,8 +54,14 @@ private:
// List of files for which we received an update since the last send
std::unordered_set<QString> m_modifiedUrls;
// When loading a project or adding many clips, adding many files to the watcher causes a freeze, so queue them
std::unordered_map<QString, QString> m_pendingUrls;
QTimer m_modifiedTimer;
QTimer m_queueTimer;
// Add a file to the list of watched items
void doAddFile(const QString &binId, const QString &url);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment