]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
xmltv: Add option to save epgdb after xmltv import.
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Tue, 2 Oct 2018 13:50:03 +0000 (14:50 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 3 Oct 2018 07:47:31 +0000 (09:47 +0200)
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.

src/epggrab.c
src/epggrab.h
src/epggrab/module.c

index 50e80c9c3f3b8f7aeb776b3e33806c312764cf8f..f727bedd198e36aec8f9774183af6adccccfcbfe 100644 (file)
@@ -321,6 +321,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",
@@ -409,6 +420,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;
 
index 58e6b7513a10bd2428c1bf1a1596309ec78de92a..cef9b837c405042085708f07bd93b40bbabbe4d3 100644 (file)
@@ -271,6 +271,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;
index 9eeae31d7181bf7c9cf0c989e5a835ce629e388f..c33e47dcd3ec33fa0cd3e399b7e44e9d4ecfcc15 100644 (file)
@@ -36,6 +36,7 @@
 #include "epg.h"
 #include "epggrab.h"
 #include "epggrab/private.h"
+extern gtimer_t epggrab_save_timer;
 
 /* **************************************************************************
  * Module Access
@@ -282,6 +283,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);
+  }
 }
 
 /* **************************************************************************