Enabled hog reindexing if Cache Sessions Data is enabled

This commit is contained in:
Mark Watkins 2012-01-10 20:26:34 +10:00
parent 2cb35b69c0
commit 1a3627f466
2 changed files with 30 additions and 13 deletions

View File

@ -327,6 +327,7 @@ bool Machine::Save()
} }
savelistCnt=0; savelistCnt=0;
savelistSize=m_savelist.size(); savelistSize=m_savelist.size();
bool cachesessions=PROFILE.session->cacheSessions();
if (!PROFILE.session->multithreading()) { if (!PROFILE.session->multithreading()) {
for (int i=0;i<savelistSize;i++) { for (int i=0;i<savelistSize;i++) {
if ((i % 10) ==0) { if ((i % 10) ==0) {
@ -336,7 +337,8 @@ bool Machine::Save()
Session *s=m_savelist.at(i); Session *s=m_savelist.at(i);
s->UpdateSummaries(); s->UpdateSummaries();
s->Store(path); s->Store(path);
s->TrashEvents(); if (!cachesessions)
s->TrashEvents();
savelistCnt++; savelistCnt++;
} }
@ -378,12 +380,15 @@ bool Machine::Save()
void SaveThread::run() void SaveThread::run()
{ {
bool cachesessions=PROFILE.session->cacheSessions();
while (Session *sess=machine->popSaveList()) { while (Session *sess=machine->popSaveList()) {
int i=(float(machine->savelistCnt)/float(machine->savelistSize)*100.0); int i=(float(machine->savelistCnt)/float(machine->savelistSize)*100.0);
emit UpdateProgress(i); emit UpdateProgress(i);
sess->UpdateSummaries(); sess->UpdateSummaries();
sess->Store(path); sess->Store(path);
sess->TrashEvents(); if (!cachesessions)
sess->TrashEvents();
} }
machine->savelistSem->release(1); machine->savelistSem->release(1);
} }

View File

@ -2513,22 +2513,28 @@ void MainWindow::doReprocessEvents()
int daycount=first.daysTo(date); int daycount=first.daysTo(date);
int idx=0; int idx=0;
//QList<Machine *> machines=PROFILE.GetMachines(MT_UNKNOWN); QList<Machine *> 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("Recalculating Summaries"));
//qstatus->setText(tr("Loading Event Data")); }
if (qprogress) {
qprogress->setValue(0); qprogress->setValue(0);
qprogress->setVisible(true); qprogress->setVisible(true);
} }
bool isopen;
QDate current=daily->getDate(); QDate current=daily->getDate();
do { do {
day=PROFILE.GetDay(date,MT_CPAP); day=PROFILE.GetDay(date,MT_CPAP);
if (day) { if (day) {
for (int i=0;i<day->size();i++) { for (int i=0;i<day->size();i++) {
sess=(*day)[i]; sess=(*day)[i];
bool isopen=sess->eventsLoaded(); isopen=sess->eventsLoaded();
// Load the events
// Load the events if they aren't loaded already
sess->OpenEvents(); sess->OpenEvents();
//if (!sess->channelDataExists(CPAP_FlowRate)) continue; //if (!sess->channelDataExists(CPAP_FlowRate)) continue;
@ -2545,9 +2551,12 @@ void MainWindow::doReprocessEvents()
sess->destroyEvent(CPAP_RDI); sess->destroyEvent(CPAP_RDI);
sess->SetChanged(true); sess->SetChanged(true);
sess->UpdateSummaries(); if (!cache_sessions) {
sess->machine()->SaveSession(sess); sess->UpdateSummaries();
if (!isopen) sess->TrashEvents(); sess->machine()->SaveSession(sess);
if (!isopen)
sess->TrashEvents();
}
} }
} }
date=date.addDays(-1); date=date.addDays(-1);
@ -2558,9 +2567,12 @@ void MainWindow::doReprocessEvents()
} while (date>=first); } while (date>=first);
// for (int i=0;i<machines.size();i++) { if (cache_sessions) {
// machines.at(i)->Save(); qstatus->setText(tr("Recalculating Summaries"));
// } for (int i=0;i<machines.size();i++) {
machines.at(i)->Save();
}
}
qstatus->setText(tr("")); qstatus->setText(tr(""));
qprogress->setVisible(false); qprogress->setVisible(false);