1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2025-02-01 18:16:45 +01:00

CollectionModel: Close database with same mutex

This commit is contained in:
Jonas Kvinge 2023-01-07 23:57:23 +01:00
parent 1c1a3fc417
commit cc4a99ad80

View File

@ -839,41 +839,43 @@ CollectionModel::QueryResult CollectionModel::RunQuery(CollectionItem *parent) {
{ {
QMutexLocker l(backend_->db()->Mutex()); QMutexLocker l(backend_->db()->Mutex());
QSqlDatabase db(backend_->db()->Connect()); {
QSqlDatabase db(backend_->db()->Connect());
CollectionQuery q(db, backend_->songs_table(), backend_->fts_table(), query_options_);
InitQuery(child_group_by, separate_albums_by_grouping_, &q);
CollectionQuery q(db, backend_->songs_table(), backend_->fts_table(), query_options_); // Walk up through the item's parents adding filters as necessary
InitQuery(child_group_by, separate_albums_by_grouping_, &q); for (CollectionItem *p = parent; p && p->type == CollectionItem::Type_Container; p = p->parent) {
FilterQuery(group_by_[p->container_level], separate_albums_by_grouping_, p, &q);
// Walk up through the item's parents adding filters as necessary
for (CollectionItem *p = parent; p && p->type == CollectionItem::Type_Container; p = p->parent) {
FilterQuery(group_by_[p->container_level], separate_albums_by_grouping_, p, &q);
}
// Artists GroupBy is special - we don't want compilation albums appearing
if (IsArtistGroupBy(child_group_by)) {
// Add the special Various artists node
if (show_various_artists_ && HasCompilations(db, q)) {
result.create_va = true;
} }
// Don't show compilations again outside the Various artists node // Artists GroupBy is special - we don't want compilation albums appearing
q.AddCompilationRequirement(false); if (IsArtistGroupBy(child_group_by)) {
} // Add the special Various artists node
if (show_various_artists_ && HasCompilations(db, q)) {
result.create_va = true;
}
// Execute the query // Don't show compilations again outside the Various artists node
if (q.Exec()) { q.AddCompilationRequirement(false);
while (q.Next()) {
result.rows << SqlRow(q);
} }
}
else { // Execute the query
backend_->ReportErrors(q); if (q.Exec()) {
while (q.Next()) {
result.rows << SqlRow(q);
}
}
else {
backend_->ReportErrors(q);
}
} }
} if (QThread::currentThread() != thread() && QThread::currentThread() != backend_->thread()) {
backend_->db()->Close();
}
if (QThread::currentThread() != thread() && QThread::currentThread() != backend_->thread()) {
backend_->Close();
} }
return result; return result;