diff --git a/SleepLib/machine.cpp b/SleepLib/machine.cpp index a6f17278..3a8318d9 100644 --- a/SleepLib/machine.cpp +++ b/SleepLib/machine.cpp @@ -327,6 +327,7 @@ bool Machine::Save() } savelistCnt=0; savelistSize=m_savelist.size(); + bool cachesessions=PROFILE.session->cacheSessions(); if (!PROFILE.session->multithreading()) { for (int i=0;iUpdateSummaries(); s->Store(path); - s->TrashEvents(); + if (!cachesessions) + s->TrashEvents(); savelistCnt++; } @@ -378,12 +380,15 @@ bool Machine::Save() void SaveThread::run() { + bool cachesessions=PROFILE.session->cacheSessions(); + while (Session *sess=machine->popSaveList()) { int i=(float(machine->savelistCnt)/float(machine->savelistSize)*100.0); emit UpdateProgress(i); sess->UpdateSummaries(); sess->Store(path); - sess->TrashEvents(); + if (!cachesessions) + sess->TrashEvents(); } machine->savelistSem->release(1); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 410581e0..c2fe6b26 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2513,22 +2513,28 @@ void MainWindow::doReprocessEvents() int daycount=first.daysTo(date); int idx=0; - //QList machines=PROFILE.GetMachines(MT_UNKNOWN); + QList machines=PROFILE.GetMachines(MT_UNKNOWN); - if (qprogress) { + bool cache_sessions=PROFILE.session->cacheSessions(); + if (cache_sessions) { // Use multithreaded save to handle reindexing.. (hogs memory like hell) + qstatus->setText(tr("Loading Event Data")); + } else { qstatus->setText(tr("Recalculating Summaries")); - //qstatus->setText(tr("Loading Event Data")); + } + if (qprogress) { qprogress->setValue(0); qprogress->setVisible(true); } + bool isopen; QDate current=daily->getDate(); do { day=PROFILE.GetDay(date,MT_CPAP); if (day) { for (int i=0;isize();i++) { sess=(*day)[i]; - bool isopen=sess->eventsLoaded(); - // Load the events + isopen=sess->eventsLoaded(); + + // Load the events if they aren't loaded already sess->OpenEvents(); //if (!sess->channelDataExists(CPAP_FlowRate)) continue; @@ -2545,9 +2551,12 @@ void MainWindow::doReprocessEvents() sess->destroyEvent(CPAP_RDI); sess->SetChanged(true); - sess->UpdateSummaries(); - sess->machine()->SaveSession(sess); - if (!isopen) sess->TrashEvents(); + if (!cache_sessions) { + sess->UpdateSummaries(); + sess->machine()->SaveSession(sess); + if (!isopen) + sess->TrashEvents(); + } } } date=date.addDays(-1); @@ -2558,9 +2567,12 @@ void MainWindow::doReprocessEvents() } while (date>=first); -// for (int i=0;iSave(); -// } + if (cache_sessions) { + qstatus->setText(tr("Recalculating Summaries")); + for (int i=0;iSave(); + } + } qstatus->setText(tr("")); qprogress->setVisible(false);