Ensure activitytracker updates get flushed to disk

This commit is contained in:
jpirnay
2026-05-23 09:55:58 +02:00
parent 39228b7631
commit f5dee12646
3 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ void ReadingSessionTracker::end() {
LOG_DBG("RST", "Session end doc=%s secs=%u pages=%u prog=%u wall=%lld", docId.c_str(), seconds, LOG_DBG("RST", "Session end doc=%s secs=%u pages=%u prog=%u wall=%lld", docId.c_str(), seconds,
pagesTurnedThisSession, lastKnownProgress, (long long)walltime); pagesTurnedThisSession, lastKnownProgress, (long long)walltime);
if (seconds > 0 && !docId.empty()) { if (!docId.empty()) {
READING_STATS.recordSession(docId, title, author, seconds, pagesTurnedThisSession, lastKnownProgress, READING_STATS.recordSession(docId, title, author, seconds, pagesTurnedThisSession, lastKnownProgress,
static_cast<time_t>(walltime)); static_cast<time_t>(walltime));
if (!READING_STATS.saveToFile()) { if (!READING_STATS.saveToFile()) {
+2 -2
View File
@@ -64,8 +64,8 @@ ReadingStatsStore ReadingStatsStore::instance;
void ReadingStatsStore::recordSession(const std::string& docId, const std::string& title, const std::string& author, void ReadingStatsStore::recordSession(const std::string& docId, const std::string& title, const std::string& author,
uint32_t sessionSeconds, uint32_t sessionPagesTurned, uint8_t progress, uint32_t sessionSeconds, uint32_t sessionPagesTurned, uint8_t progress,
time_t walltimeEpoch) { time_t walltimeEpoch) {
if (docId.empty() || sessionSeconds == 0) { if (docId.empty()) {
// Nothing to credit. Title-update-only flows go through a different path. // Title-update-only flows go through a different path.
return; return;
} }
+5
View File
@@ -28,6 +28,7 @@
#include "KOReaderCredentialStore.h" #include "KOReaderCredentialStore.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "OpdsServerStore.h" #include "OpdsServerStore.h"
#include "ReadingSessionTracker.h"
#include "ReadingStats.h" #include "ReadingStats.h"
#include "RecentBooksStore.h" #include "RecentBooksStore.h"
#include "SdCardFontSystem.h" #include "SdCardFontSystem.h"
@@ -154,6 +155,9 @@ static bool deepSleepInProgress = false;
void silentRestart() { void silentRestart() {
if (deepSleepInProgress) return; // sleeping supersedes the heap-defrag reboot if (deepSleepInProgress) return; // sleeping supersedes the heap-defrag reboot
// ESP.restart() bypasses activity onExit(), so flush any in-flight reading
// session manually — otherwise a heap-defrag reboot mid-read loses the session.
globalReadingSessionTracker().end();
silentRebootTarget = SILENT_REBOOT_TARGET_HOME; silentRebootTarget = SILENT_REBOOT_TARGET_HOME;
silentRebootMagic = SILENT_REBOOT_MAGIC; silentRebootMagic = SILENT_REBOOT_MAGIC;
LOG_DBG("MAIN", "Silent restart (target=home)"); LOG_DBG("MAIN", "Silent restart (target=home)");
@@ -163,6 +167,7 @@ void silentRestart() {
void silentRestartToReader() { void silentRestartToReader() {
if (deepSleepInProgress) return; // sleeping supersedes the heap-defrag reboot if (deepSleepInProgress) return; // sleeping supersedes the heap-defrag reboot
globalReadingSessionTracker().end();
silentRebootTarget = SILENT_REBOOT_TARGET_READER; silentRebootTarget = SILENT_REBOOT_TARGET_READER;
silentRebootMagic = SILENT_REBOOT_MAGIC; silentRebootMagic = SILENT_REBOOT_MAGIC;
LOG_DBG("MAIN", "Silent restart (target=reader)"); LOG_DBG("MAIN", "Silent restart (target=reader)");