From 8900905e525f6a793b52f17c5e6d83d9fef00675 Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Sat, 21 Mar 2009 20:27:45 +0000 Subject: [PATCH] This is a patch to quicken the populating of filesets and clients. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8575 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/clients/clients.cpp | 34 +++++++++++++---------- bacula/src/qt-console/fileset/fileset.cpp | 30 +++++++++++++------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/bacula/src/qt-console/clients/clients.cpp b/bacula/src/qt-console/clients/clients.cpp index 9f82e278aa..95c5892549 100644 --- a/bacula/src/qt-console/clients/clients.cpp +++ b/bacula/src/qt-console/clients/clients.cpp @@ -98,27 +98,33 @@ void Clients::populateTable() tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */ - int row = 0; - + bool first = true; + QString client_comsep(""); foreach (QString clientName, m_console->client_list){ - /* Set up query QString and header QStringList */ + if (first) { + client_comsep += "'" + clientName + "'"; + first = false; + } + else + client_comsep += ",'" + clientName + "'"; + } + + if (client_comsep != "") { QString query(""); query += "SELECT Name, FileRetention, JobRetention, AutoPrune, ClientId, Uname" " FROM Client" - " WHERE "; - query += " Name='" + clientName + "'"; - query += " ORDER BY ClientId LIMIT 1"; + " WHERE ClientId IN (SELECT MAX(ClientId) FROM Client WHERE"; + query += " Name IN (" + client_comsep + ")"; + query += " GROUP BY Name) ORDER BY Name"; QStringList results; - /* This could be a log item */ - if (mainWin->m_sqlDebug) { + if (mainWin->m_sqlDebug) Pmsg1(000, "Clients query cmd : %s\n",query.toUtf8().data()); - } if (m_console->sql_cmd(query, results)) { - int resultCount = results.count(); - if (resultCount){ - /* only use the last one */ - QString resultline = results[resultCount - 1]; + int row = 0; + + /* Iterate through the record returned from the query */ + foreach (QString resultline, results) { QStringList fieldlist = resultline.split("\t"); TableItemFormatter item(*tableWidget, row); @@ -145,9 +151,9 @@ void Clients::populateTable() /* uname */ item.setTextFld(col++, fld.next()); + row++; } } - row ++; } /* set default sorting */ tableWidget->sortByColumn(sortcol, sortord); diff --git a/bacula/src/qt-console/fileset/fileset.cpp b/bacula/src/qt-console/fileset/fileset.cpp index cbf3acaf78..57b309a786 100644 --- a/bacula/src/qt-console/fileset/fileset.cpp +++ b/bacula/src/qt-console/fileset/fileset.cpp @@ -90,28 +90,38 @@ void FileSet::populateTable() tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */ - int row = 0; + QString fileset_comsep(""); + bool first = true; foreach(QString filesetName, m_console->fileset_list) { + if (first) { + fileset_comsep += "'" + filesetName + "'"; + first = false; + } + else + fileset_comsep += ",'" + filesetName + "'"; + } + if (fileset_comsep != "") { /* Set up query QString and header QStringList */ QString query(""); query += "SELECT FileSet AS Name, FileSetId AS Id, CreateTime" " FROM FileSet" - " WHERE "; - query += " FileSet='" + filesetName + "'"; - query += " ORDER BY CreateTime DESC LIMIT 1"; + " WHERE FileSetId IN (SELECT MAX(FileSetId) FROM FileSet WHERE"; + query += " FileSet IN (" + fileset_comsep + ")"; + query += " GROUP BY FileSet) ORDER BY FileSet"; QStringList results; if (mainWin->m_sqlDebug) { Pmsg1(000, "FileSet query cmd : %s\n",query.toUtf8().data()); } if (m_console->sql_cmd(query, results)) { - int resultCount = results.count(); - if (resultCount) { - /* only use the last one */ - QString resultline = results[resultCount - 1]; - QStringList fieldlist = resultline.split("\t"); + int row = 0; + QStringList fieldlist; + + /* Iterate through the record returned from the query */ + foreach (QString resultline, results) { + fieldlist = resultline.split("\t"); TableItemFormatter item(*tableWidget, row); @@ -128,9 +138,9 @@ void FileSet::populateTable() /* creation time */ item.setTextFld(col++, fld.next()); + row++; } } - row++; } /* set default sorting */ tableWidget->sortByColumn(headerlist.indexOf(tr("Create Time")), Qt::DescendingOrder); -- 2.39.5