]> 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)
committerperexg <perex@perex.cz>
Tue, 2 Oct 2018 16:39:02 +0000 (18:39 +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 0fe94be1256c9342c3858abef34d842e99d07e8c..ee158f768fbad5c8fc6277ac6a1c57df893f2e9d 100644 (file)
@@ -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;
 
index 1ce5b1dbcfa90b6465d963f7be2052b61a1188d3..1a589b628c66b106c80db779abcf957d44de64e4 100644 (file)
@@ -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;
index 8b571a8f75c33b80976cd22a280505c2cac7f031..bf4a9533aa0e6b13f729bff526b88ea2090af018 100644 (file)
@@ -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);
+  }
 }
 
 /* **************************************************************************