Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit c5fb7af

Browse files
committed
preformance improvements
1 parent 444478f commit c5fb7af

32 files changed

+737
-339
lines changed

src/Ramses.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ SOURCES += \
5656
ramobjectmodels/ramfilterlistproxymodel.cpp \
5757
ramobjectmodels/ramobjectmodel.cpp \
5858
ramobjectmodels/ramobjectsortfilterproxymodel.cpp \
59+
ramobjectmodels/ramschedulemodel.cpp \
5960
ramobjectmodels/ramstatustablemodel.cpp \
6061
ramobjectmodels/statisticsmodel.cpp \
6162
ramobjectmodels/timelineproxy.cpp \
@@ -194,6 +195,7 @@ SOURCES += \
194195
rameditwidgets/templateassetgroupeditwidget.cpp \
195196
rameditwidgets/templatestepeditwidget.cpp \
196197
rameditwidgets/usereditwidget.cpp \
198+
statemanager.cpp \
197199
timelinemanager.cpp \
198200
userprofilepage.cpp \
199201
rammanagerwidgets/itemmanagerwidget.cpp \
@@ -221,6 +223,7 @@ HEADERS += \
221223
ramobjectmodels/ramfilterlistproxymodel.h \
222224
ramobjectmodels/ramobjectmodel.h \
223225
ramobjectmodels/ramobjectsortfilterproxymodel.h \
226+
ramobjectmodels/ramschedulemodel.h \
224227
ramobjectmodels/ramstatustablemodel.h \
225228
ramobjectmodels/statisticsmodel.h \
226229
ramobjectmodels/timelineproxy.h \
@@ -361,6 +364,7 @@ HEADERS += \
361364
rameditwidgets/templateassetgroupeditwidget.h \
362365
rameditwidgets/templatestepeditwidget.h \
363366
rameditwidgets/usereditwidget.h \
367+
statemanager.h \
364368
timelinemanager.h \
365369
userprofilepage.h \
366370
rammanagerwidgets/itemmanagerwidget.h \

src/duqf-app/app-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define VERSION_MAJOR 0
55
#define VERSION_MINOR 8
6-
#define VERSION_BUILD 5
6+
#define VERSION_BUILD 6
77
#define VERSION_SUFFIX "Beta"
88

99
#define STRINGIFY_VERSION(A, B, C) CONCAT(A, B, C )

src/ramdatainterface/dbinterface.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ bool DBInterface::isRemoved(QString uuid, QString table)
101101
return m_ldi->isRemoved(uuid, table);
102102
}
103103

104+
QString DBInterface::modificationDate(QString uuid, QString table)
105+
{
106+
return m_ldi->modificationDate(uuid, table);
107+
}
108+
104109
void DBInterface::setUsername(QString uuid, QString username)
105110
{
106111
m_ldi->setUsername(uuid, username);
@@ -120,10 +125,16 @@ const QString &DBInterface::dataFile() const
120125

121126
void DBInterface::setDataFile(const QString &file, bool ignoreUser)
122127
{
128+
QElapsedTimer openTimer;
129+
openTimer.start();
130+
123131
ProgressManager *pm = ProgressManager::instance();
124132
pm->setText(tr("Loading database..."));
125133

126134
ServerConfig config = m_ldi->setDataFile(file);
135+
136+
qDebug() << "> Database set: " << openTimer.elapsed()/1000 << " seconds.";
137+
127138
// Set the new server params
128139
if (config.address != "")
129140
{
@@ -139,11 +150,16 @@ void DBInterface::setDataFile(const QString &file, bool ignoreUser)
139150
// Check the user
140151
QString userUuid = m_ldi->currentUserUuid();
141152

142-
qDebug() << "Selected previous user: " << userUuid;
153+
qDebug() << "> Selecting previous user: " << userUuid;
143154

144155
emit userChanged( userUuid );
156+
157+
qDebug() << "> Selected user: " << openTimer.elapsed()/1000 << " seconds.";
158+
145159
setOnline(serverUuid);
146160

161+
qDebug() << "> Online! " << openTimer.elapsed()/1000 << " seconds.";
162+
147163
pm->setText(tr("Ready!"));
148164
pm->finish();
149165
}
@@ -218,6 +234,8 @@ void DBInterface::setDataFile(const QString &file, bool ignoreUser)
218234
return;
219235
}
220236
}
237+
238+
qDebug() << "> DB Ready! " << openTimer.elapsed()/1000 << " seconds.";
221239
}
222240

223241
void DBInterface::setCurrentUserUuid(QString uuid)

src/ramdatainterface/dbinterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class DBInterface : public DuQFLoggerObject
6464
void restoreObject(QString uuid, QString table);
6565
bool isRemoved(QString uuid, QString table);
6666

67+
QString modificationDate(QString uuid, QString table);
68+
6769
void setUsername(QString uuid, QString username);
6870
bool isUserNameAavailable(const QString &userName);
6971

src/ramdatainterface/localdatainterface.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "duqf-app/app-version.h"
66
#include "duqf-utils/utils.h"
77
#include "progressmanager.h"
8+
#include "statemanager.h"
89
#include "ramuser.h"
910
#include "ramses.h"
1011

@@ -371,6 +372,19 @@ bool LocalDataInterface::isRemoved(QString uuid, QString table)
371372
return true;
372373
}
373374

375+
QString LocalDataInterface::modificationDate(QString uuid, QString table)
376+
{
377+
QString q = "SELECT modified FROM %1 WHERE uuid = '%2';";
378+
QSqlQuery qry = query( q.arg(table, uuid) );
379+
380+
if (qry.first())
381+
{
382+
return qry.value(0).toString();
383+
}
384+
385+
return "1818-05-05 00:00:00";
386+
}
387+
374388
void LocalDataInterface::setUsername(QString uuid, QString username)
375389
{
376390
username.replace("'", "''");
@@ -490,16 +504,25 @@ const QString &LocalDataInterface::dataFile() const
490504

491505
ServerConfig LocalDataInterface::setDataFile(const QString &file)
492506
{
507+
QElapsedTimer timer;
508+
timer.start();
509+
510+
qDebug() << ">> Opening local file...";
511+
493512
// Clear all cache
494513
m_uuids.clear();
495514
m_uuidsWithoutRemoved.clear();
496515

516+
qDebug() << ">> Cleared cache: " << timer.elapsed()/1000 << " seconds.";
517+
497518
ProgressManager *pm = ProgressManager::instance();
498519
pm->addToMaximum(2);
499520

500521
QSqlDatabase db = QSqlDatabase::database("localdata");
501522
openDB(db, file);
502523

524+
qDebug() << ">> Opened file: " << timer.elapsed()/1000 << " seconds.";
525+
503526
pm->increment();
504527
pm->setText(tr("Loading data..."));
505528

@@ -542,6 +565,8 @@ ServerConfig LocalDataInterface::setDataFile(const QString &file)
542565

543566
pm->increment();
544567

568+
qDebug() << ">> Local data ready! " << timer.elapsed()/1000 << " seconds.";
569+
545570
return serverConfig();
546571
}
547572

@@ -623,6 +648,9 @@ SyncData LocalDataInterface::getSync(bool fullSync)
623648

624649
void LocalDataInterface::saveSync(SyncData syncData)
625650
{
651+
StateManager::State previousState = StateManager::i()->state();
652+
StateManager::i()->setState(StateManager::WritingDataBase);
653+
626654
QHash<QString, QSet<TableRow>> tables = syncData.tables;
627655

628656
ProgressManager *pm = ProgressManager::instance();
@@ -706,11 +734,14 @@ void LocalDataInterface::saveSync(SyncData syncData)
706734
query( q );
707735

708736
// Emit insertions
737+
StateManager::i()->setState(StateManager::LoadingDataBase);
709738
foreach(QStringList io, insertedObjects ) {
710739
emit inserted( io.at(0), io.at(1), io.at(2) );
711740
}
712741
}
713742

743+
StateManager::i()->setState(StateManager::WritingDataBase);
744+
714745
// Updates
715746
i.toFront();
716747
while (i.hasNext()) {
@@ -795,12 +826,15 @@ void LocalDataInterface::saveSync(SyncData syncData)
795826
query( q );
796827

797828
// Emit
829+
StateManager::i()->setState(StateManager::LoadingDataBase);
798830
foreach(QStringList cu, changedUuids) {
799831
emit dataChanged(cu.first(), cu.last(), tableName);
800832
}
801833
}
802834

803835
emit syncFinished();
836+
837+
StateManager::i()->setState(previousState);
804838
}
805839

806840
void LocalDataInterface::deleteData(SyncData syncData)
@@ -930,6 +964,9 @@ QVector<QStringList> LocalDataInterface::users()
930964

931965
QString LocalDataInterface::cleanDataBase(int deleteDataOlderThan)
932966
{
967+
StateManager::State previousState = StateManager::i()->state();
968+
StateManager::i()->setState(StateManager::WritingDataBase);
969+
933970
QString report = "";
934971

935972
// Backup the DB File
@@ -1030,6 +1067,8 @@ QString LocalDataInterface::cleanDataBase(int deleteDataOlderThan)
10301067

10311068
qDebug() << "Finished clean.";
10321069

1070+
StateManager::i()->setState(previousState);
1071+
10331072
return report;
10341073
}
10351074

@@ -1081,7 +1120,7 @@ LocalDataInterface::LocalDataInterface():
10811120
}
10821121

10831122
bool LocalDataInterface::openDB(QSqlDatabase db, const QString &dbFile)
1084-
{
1123+
{
10851124
ProgressManager *pm = ProgressManager::instance();
10861125
pm->addToMaximum(2);
10871126
pm->setText(tr("Opening database..."));
@@ -1230,6 +1269,9 @@ void LocalDataInterface::autoCleanDB(QSqlDatabase db)
12301269
if ( !db.open() ) return;
12311270
}
12321271

1272+
StateManager::State previousState = StateManager::i()->state();
1273+
StateManager::i()->setState(StateManager::WritingDataBase);
1274+
12331275
// === Delete removed statuses ===
12341276

12351277
qry.exec("DELETE FROM RamStatus WHERE `removed` = 1 ;");
@@ -1442,6 +1484,8 @@ void LocalDataInterface::autoCleanDB(QSqlDatabase db)
14421484
// === Vacuum ===
14431485

14441486
qry.exec("VACUUM;");
1487+
1488+
StateManager::i()->setState(previousState);
14451489
}
14461490

14471491
QSqlQuery LocalDataInterface::query(QString q) const

src/ramdatainterface/localdatainterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class LocalDataInterface : public DuQFLoggerObject
4646
void restoreObject(QString uuid, QString table);
4747
bool isRemoved(QString uuid, QString table);
4848

49+
QString modificationDate(QString uuid, QString table);
50+
4951
void setUsername(QString uuid, QString username);
5052
bool isUserNameAavailable(const QString &userName);
5153
void updateUser(QString uuid, QString username, QString data, QString modified);

src/ramdatainterface/ramserverinterface.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "ramdatainterface/localdatainterface.h"
77
#include "ramdatainterface/logindialog.h"
88
#include "duqf-utils/guiutils.h"
9+
#include "statemanager.h"
910

1011
// STATIC //
1112

@@ -226,6 +227,9 @@ void RamServerInterface::eraseUserPassword()
226227

227228
void RamServerInterface::login()
228229
{
230+
StateManager::State previousState = StateManager::i()->state();
231+
StateManager::i()->setState(StateManager::Connecting);
232+
229233
setConnectionStatus(NetworkUtils::Connecting, "Logging in...");
230234

231235
// Check if we have saved credentials
@@ -253,6 +257,7 @@ void RamServerInterface::login()
253257
if (username != "" && password != "")
254258
{
255259
doLogin(username, password, true, true);
260+
StateManager::i()->setState(previousState);
256261
return;
257262
}
258263

@@ -271,6 +276,8 @@ void RamServerInterface::login()
271276

272277
// Wait for the dialog to return
273278
loop.exec();
279+
280+
StateManager::i()->setState(previousState);
274281
}
275282

276283
void RamServerInterface::sync(SyncData syncData)

src/rammanagerwidgets/schedulemanagerwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ void ScheduleManagerWidget::changeProject()
825825
if (!m_project)
826826
{
827827
this->setEnabled(false);
828-
m_schedule->setObjectModel(nullptr, nullptr);
828+
m_schedule->setObjectModel(nullptr, nullptr, nullptr);
829829
ui_userMenu->setObjectModel(nullptr);
830830
ui_endDateEdit->setDate(QDate::currentDate());
831831
ui_stepMenu->setObjectModel(nullptr);
@@ -835,7 +835,7 @@ void ScheduleManagerWidget::changeProject()
835835
}
836836
this->setEnabled(true);
837837

838-
m_schedule->setObjectModel( m_project->users(), m_project->scheduleComments() );
838+
m_schedule->setObjectModel( m_project->users(), m_project->schedule(), m_project->scheduleComments() );
839839

840840
ui_userMenu->setObjectModel( m_project->users() );
841841
ui_endDateEdit->setDate( QDate::currentDate().addDays(30) );

src/ramobjectmodels/dbtablemodel.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
#include "dbinterface.h"
44
#include "progressmanager.h"
55

6-
DBTableModel::DBTableModel(RamObject::ObjectType type, bool projectTable, QObject *parent):
6+
DBTableModel::DBTableModel(RamObject::ObjectType type, bool projectTable, bool sorted, QObject *parent):
77
RamAbstractObjectModel{type, parent}
88
{
99
m_isProjectTable = projectTable;
10+
m_userOrder = sorted;
1011
}
1112

1213
void DBTableModel::addFilterValue(QString key, QString value)
@@ -137,12 +138,13 @@ void DBTableModel::insertObjects(int row, QVector<QStringList> data, QString tab
137138
// Insert
138139
if (!silent) beginInsertRows(QModelIndex(), row, row + data.count()-1);
139140

141+
//qDebug() << "Inserting " << data.count() << " objects in " << table;
142+
140143
for (int i = data.count() - 1; i >= 0; i--)
141144
{
142145
QStringList obj = data.at(i);
143146
QString uuid = obj.first();
144147
QString dataStr = obj.at(1);
145-
146148
RamAbstractObjectModel::insertObject(row, uuid, dataStr);
147149
}
148150

@@ -208,6 +210,7 @@ bool DBTableModel::checkFilters(QString data) const
208210

209211
void DBTableModel::saveOrder() const
210212
{
213+
if (!m_userOrder) return;
211214
// Save order
212215
for (int i = 0; i <= rowCount(); i++)
213216
{
@@ -243,7 +246,8 @@ void DBTableModel::insertObject(QString uuid, QString data, QString table)
243246
if (!checkFilters(data)) return;
244247

245248
// Check order
246-
int order = getOrder(data);
249+
int order = m_objectUuids.count();
250+
if (m_userOrder) order = getOrder(data);
247251

248252
// Insert
249253
QStringList o;
@@ -270,9 +274,17 @@ void DBTableModel::reload()
270274

271275
// Get all
272276
QVector<QStringList> objs = LocalDataInterface::instance()->tableData( m_table, m_filters );
273-
//qDebug() << "Got " << objs.count() << " objects from " << m_table;
277+
278+
qDebug() << "Got " << objs.count() << " objects from " << m_table;
279+
274280
// Sort
275-
std::sort(objs.begin(), objs.end(), objSorter);
281+
if (m_userOrder) {
282+
std::sort(objs.begin(), objs.end(), objSorter);
283+
qDebug() << "Objects sorted";
284+
} else {
285+
qDebug() << "Table not sorted";
286+
}
287+
276288
// Insert
277289
insertObjects(0, objs, m_table, true);
278290

0 commit comments

Comments
 (0)