Ignore old sessions should not impact existing data

This commit is contained in:
kappa44 2021-05-18 20:45:04 +10:00
parent 497cf8e5c4
commit a836871914
3 changed files with 13 additions and 5 deletions

View File

@ -49,6 +49,7 @@
<li>[fix] Stop skipping the first 40 seconds of ResMed low-rate pressure data.</li>
<li>[fix] Correct Total Time and AHI in CSV Export when non-CPAP devices are used.</li>
<li>[fix] Fix value display and bookmark behavior with clock drift.</li>
<li>[fix] Ignore old sessions should not impact existing data.</li>
</ul>
<p>
<b>Changes and fixes in OSCAR v1.2.0</b>

View File

@ -279,7 +279,11 @@ QDate Machine::pickDate(qint64 first)
return date;
}
bool Machine::AddSession(Session *s)
// allowOldSessions defaults to false and is only set to true when loading
// summary data on profile load. This true setting prevents old sessions from
// becoming lost if user preference indicates to not import sessions prior to a
// given date.
bool Machine::AddSession(Session *s, bool allowOldSessions)
{
if (s == nullptr) {
qCritical() << "AddSession() called with a null object";
@ -303,7 +307,10 @@ bool Machine::AddSession(Session *s)
return false;
}
if (profile->session->ignoreOlderSessions()) {
// allowOldSessions is true when loading summaries (already imported sessions)
// We don't want to throw away data already in the database in circumstances
// where user wants to ignore old sessions on import.
if (profile->session->ignoreOlderSessions() && !allowOldSessions) {
qint64 ignorebefore = profile->session->ignoreOlderSessionsDate().toMSecsSinceEpoch();
if (s->last() < ignorebefore) {
qDebug() << s->session() << "Ignoring old session";
@ -783,7 +790,7 @@ bool Machine::Load(ProgressDialog *progress)
// Forced to load it, because know nothing about this session..
if (sess->LoadSummary()) {
AddSession(sess);
AddSession(sess, true);
} else {
qWarning() << "Error loading summary file" << filename;
delete sess;
@ -1019,7 +1026,7 @@ bool Machine::LoadSummary(ProgressDialog * progress)
// }
*****************************************************************/
Session * sess = it.value();
if ( ! AddSession(sess)) {
if ( ! AddSession(sess, true)) {
delete sess;
} else {
if (loadSummaries) {

View File

@ -143,7 +143,7 @@ class Machine
Session *SessionExists(SessionID session);
//! \brief Adds the session to this machine object, and the Master Profile list. (used during load)
bool AddSession(Session *s);
bool AddSession(Session *s, bool allowOldSessions=false);
//! \brief Find the date this session belongs in, according to profile settings
QDate pickDate(qint64 start);