Skip to content

Commit

Permalink
Fix EPG update being aborted prematurely when requesting guide data f…
Browse files Browse the repository at this point in the history
…rom the past
  • Loading branch information
djp952 committed Aug 3, 2017
1 parent fd49c88 commit 90f7f85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions pvr.hdhomerundvr/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.2.2 (2017.08.02)
- Fix EPG update being aborted prematurely when requesting guide data from the past

v1.2.1 (2017.08.02)
- Add "Disable Channel", "Add to Favorite Channels" and "Remove from Favorite Channels" Client Actions to channel context menus
- Adapt to new backend discovery URLs (api.hdhomerun.com)
Expand Down
20 changes: 14 additions & 6 deletions src/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,10 @@ void enumerate_guideentries(sqlite3* instance, union channelid channelid, time_t

if((instance == nullptr) || (callback == nullptr)) return;

// Prevent asking for anything older than 4 hours in the past (14400 = (60 * 60 * 4) = 4 hours)
time_t now = time(nullptr);
starttime = std::max(starttime, now - 14400);

// seriesid | title | starttime | endtime | synopsis | year | iconurl | genretype | originalairdate | seriesnumber | episodenumber | episodename
auto sql = "with deviceauth(code) as (select group_concat(json_extract(data, '$.DeviceAuth'), '') from device) "
"select json_extract(entry.value, '$.SeriesID') as seriesid, "
Expand All @@ -1418,7 +1422,7 @@ void enumerate_guideentries(sqlite3* instance, union channelid channelid, time_t

try {

do {
while(starttime < endtime) {

// Bind the query parameters
result = sqlite3_bind_int(statement, 1, channelid.value);
Expand All @@ -1428,10 +1432,15 @@ void enumerate_guideentries(sqlite3* instance, union channelid channelid, time_t
// Execute the SQL statement
result = sqlite3_step(statement);

// If no rows were returned from the query, there is no more available guide data
// from the backend, break the loop even though endtime may not have been reached
if(result == SQLITE_DONE) break;
// If no rows were returned from the query and the start time is still in the past,
// fast-forward it to the current time and try again. Otherwise stop - no more data
if(result == SQLITE_DONE) {

if(starttime < now) starttime = now;
else break;
}

// Process each row returned from the query (if any)
while(result == SQLITE_ROW) {

struct guideentry item;
Expand Down Expand Up @@ -1459,8 +1468,7 @@ void enumerate_guideentries(sqlite3* instance, union channelid channelid, time_t
// Reset the prepared statement so that it can be executed again
result = sqlite3_reset(statement);
if(result != SQLITE_OK) throw sqlite_exception(result);

} while(starttime < endtime);
};

sqlite3_finalize(statement); // Finalize the SQLite statement
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
Company=Michael G. Brehm
Copyright=
Product=zuki.pvr.hdhomerundvr
Version=1.2.1
Version=1.2.2

0 comments on commit 90f7f85

Please sign in to comment.