Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Backend : public QObject {
// Called for org.freedesktop.FileManager1: open a folder, or open the
// folder holding a file and select it.
void showFolder(const QString &path);
void showItem(const QString &path);
Q_INVOKABLE void showItem(const QString &path);

static QString expandTyped(const QString &text, const QString &home, const QString &current);
static QString complete(const QString &text, const QString &home, const QString &current);
Expand Down
25 changes: 23 additions & 2 deletions src/foldermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ FolderModel::~FolderModel() {
*m_latest = 0;
}

// Folder listings run on a pool of their own, apart from the folder counts
// and previews on the global one: slow or huge subfolders being counted can't
// then hold up the listing of the folder just opened.
static QThreadPool &listingPool() {
static QThreadPool *const pool = [] {
auto *p = new QThreadPool;
p->setMaxThreadCount(8);
return p;
}();
return *pool;
}

static QThreadPool &countingPool() {
static QThreadPool *const pool = [] {
auto *p = new QThreadPool;
p->setMaxThreadCount(2);
return p;
}();
return *pool;
}

// Recent listings, shared by every model (the window's folder and each
// column), so stepping back and forth or opening a column for a folder just
// seen shows it in the same frame instead of an old or empty one. Each is
Expand Down Expand Up @@ -481,7 +502,7 @@ void FolderModel::reload() {
remember();
countFolders(generation);
});
watcher->setFuture(QtConcurrent::run([path, showHidden, sort, query, items, latest, generation, locale] {
watcher->setFuture(QtConcurrent::run(&listingPool(), [path, showHidden, sort, query, items, latest, generation, locale] {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Cancellation test controls wrong pool

folderModelStopsReadingWhatsBeenOvertaken still limits the global pool to one thread, but listings now use listingPool() with eight threads. The next listing can finish on another thread even if the old read never stops, so the test no longer checks cancellation. Update the test to constrain the pool that actually runs listings, or check cancellation directly.

QString error;
const auto overtaken = [&] { return *latest != generation; };
auto entries = isPluginView(path) ? listItems(items, query)
Expand Down Expand Up @@ -524,7 +545,7 @@ void FolderModel::countFolders(quint64 generation) {
remember();
});
const auto latest = m_latest;
watcher->setFuture(QtConcurrent::run([folders, showHidden, latest, generation]() mutable {
watcher->setFuture(QtConcurrent::run(&countingPool(), [folders, showHidden, latest, generation]() mutable {
// Overtaken (another folder, or a re-read), the counts would be
// thrown away, so it stops instead of listing every subfolder.
for (auto &folder : folders) {
Expand Down