From: E.Smith <31170571+azlm8t@users.noreply.github.com> Date: Tue, 2 Oct 2018 13:50:03 +0000 (+0100) Subject: xmltv: Add option to save epgdb after xmltv import. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d96fef9120557b7c33a56a8dfdcede48159c752e;p=thirdparty%2Ftvheadend.git xmltv: Add option to save epgdb after xmltv import. The "periodic save database" means that for xmltv you can import your daily listings, crash, restart, and not have xmltv data since the periodic epgdb timer has not elapsed. So, add an option so the user can save the database after the import has completed, assuming changes occurred. This save is delayed by a couple of minutes in case the user is importing from several different xmltv guides, in which case the save occurs after the last import. --- diff --git a/src/epggrab.c b/src/epggrab.c index 0fe94be12..ee158f768 100644 --- a/src/epggrab.c +++ b/src/epggrab.c @@ -400,6 +400,17 @@ const idclass_t epggrab_class = { .off = offsetof(epggrab_conf_t, epgdb_periodicsave), .group = 1, }, + { + .type = PT_BOOL, + .id = "epgdb_saveafterimport", + .name = N_("Save EPG to disk after xmltv import"), + .desc = N_("Writes the current in-memory EPG database to disk " + "shortly after an xmltv import has completed, so should a crash/unexpected " + "shutdown occur EPG data is saved " + "(re-read on next startup)."), + .off = offsetof(epggrab_conf_t, epgdb_saveafterimport), + .group = 1, + }, { .type = PT_STR, .id = "cron", @@ -484,6 +495,7 @@ void epggrab_init ( void ) epggrab_conf.channel_renumber = 0; epggrab_conf.channel_reicon = 0; epggrab_conf.epgdb_periodicsave = 0; + epggrab_conf.epgdb_saveafterimport = 0; epggrab_cron_multi = NULL; diff --git a/src/epggrab.h b/src/epggrab.h index 1ce5b1dbc..1a589b628 100644 --- a/src/epggrab.h +++ b/src/epggrab.h @@ -320,6 +320,7 @@ typedef struct epggrab_conf { uint32_t channel_renumber; uint32_t channel_reicon; uint32_t epgdb_periodicsave; + uint32_t epgdb_saveafterimport; char *ota_cron; uint32_t ota_timeout; uint32_t ota_initial; diff --git a/src/epggrab/module.c b/src/epggrab/module.c index 8b571a8f7..bf4a9533a 100644 --- a/src/epggrab/module.c +++ b/src/epggrab/module.c @@ -36,6 +36,7 @@ #include "epg.h" #include "epggrab.h" #include "epggrab/private.h" +extern gtimer_t epggrab_save_timer; /* ************************************************************************** * Module Access @@ -406,6 +407,25 @@ void epggrab_module_parse( void *m, htsmsg_t *data ) tvhinfo(mod->subsys, "%s: broadcasts tot=%5d new=%5d mod=%5d", mod->id, stats.broadcasts.total, stats.broadcasts.created, stats.broadcasts.modified); + + /* Now we've parsed, do we need to save? */ + if (save && epggrab_conf.epgdb_saveafterimport) { + tvhinfo(mod->subsys, "%s: scheduling save epg timer", mod->id); + pthread_mutex_lock(&global_lock); + /* Disarm any existing timer first (from a periodic save). */ + gtimer_disarm(&epggrab_save_timer); + /* Reschedule for a few minutes away so if the user is + * refreshing from multiple xmltv sources we will give time for + * them to all complete before persisting, rather than persisting + * immediately after a parse. + * + * If periodic saving is enabled then the callback will then + * rearm the timer for x hours after the previous save. + */ + gtimer_arm_rel(&epggrab_save_timer, epg_save_callback, NULL, + 60 * 2); + pthread_mutex_unlock(&global_lock); + } } /* **************************************************************************