From 084d8936e356adcdb833244311b203a1b3978538 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Thu, 4 Jan 2018 21:21:45 +0000
Subject: mythtv, mythplugins, mythweb: update to latest fixes

---
 abs/core/mythtv/stable-29/git_src/git_hash         |   2 +-
 abs/core/mythtv/stable-29/git_src/git_hash_web     |   2 +-
 abs/core/mythtv/stable-29/mythplugins/PKGBUILD     |   2 +-
 ...dbase-cache-for-RegisterKey-and-RegisterJ.patch | 276 +++++++++++++++++++++
 abs/core/mythtv/stable-29/mythtv/PKGBUILD          |   4 +-
 abs/core/mythtv/stable-29/mythweb/PKGBUILD         |   2 +-
 6 files changed, 283 insertions(+), 5 deletions(-)
 create mode 100644 abs/core/mythtv/stable-29/mythtv/0259-0117-UI-Provide-dbase-cache-for-RegisterKey-and-RegisterJ.patch

diff --git a/abs/core/mythtv/stable-29/git_src/git_hash b/abs/core/mythtv/stable-29/git_src/git_hash
index d869e90..c3edd34 100644
--- a/abs/core/mythtv/stable-29/git_src/git_hash
+++ b/abs/core/mythtv/stable-29/git_src/git_hash
@@ -1 +1 @@
-39b2062c069e801c9f9c4b15d198e8ef72594f55
+9dbf6706337b72b132f34d6c8e9f305609a44d7e
diff --git a/abs/core/mythtv/stable-29/git_src/git_hash_web b/abs/core/mythtv/stable-29/git_src/git_hash_web
index 5d42c24..38dfcdc 100644
--- a/abs/core/mythtv/stable-29/git_src/git_hash_web
+++ b/abs/core/mythtv/stable-29/git_src/git_hash_web
@@ -1 +1 @@
-6db62758ba7f06eb916a041292f50ec298cc01b0
+99838ff4323d7dfc20fd720d4ed3a2042592df69
diff --git a/abs/core/mythtv/stable-29/mythplugins/PKGBUILD b/abs/core/mythtv/stable-29/mythplugins/PKGBUILD
index 35d18e4..13c6da2 100644
--- a/abs/core/mythtv/stable-29/mythplugins/PKGBUILD
+++ b/abs/core/mythtv/stable-29/mythplugins/PKGBUILD
@@ -9,7 +9,7 @@ pkgname=('mytharchive'
          'mythweather'
          'mythzoneminder')
 pkgver=29
-pkgrel=7
+pkgrel=8
 arch=('i686' 'x86_64')
 url="http://www.mythtv.org"
 license=('GPL')
diff --git a/abs/core/mythtv/stable-29/mythtv/0259-0117-UI-Provide-dbase-cache-for-RegisterKey-and-RegisterJ.patch b/abs/core/mythtv/stable-29/mythtv/0259-0117-UI-Provide-dbase-cache-for-RegisterKey-and-RegisterJ.patch
new file mode 100644
index 0000000..79169e4
--- /dev/null
+++ b/abs/core/mythtv/stable-29/mythtv/0259-0117-UI-Provide-dbase-cache-for-RegisterKey-and-RegisterJ.patch
@@ -0,0 +1,276 @@
+From 53ab06dc745938d2ea74214fc10a2b5446bac01a Mon Sep 17 00:00:00 2001
+From: Lawrence Rust <lvr@softsystem.co.uk>
+Date: Wed, 5 Jun 2013 16:07:56 +0100
+Subject: [PATCH 117/333] UI: Provide dbase cache for RegisterKey and
+ RegisterJump to speed startup
+
+Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
+---
+ mythtv/libs/libmythui/mythmainwindow.cpp |  211 +++++++++++++++++++++---------
+ 1 file changed, 147 insertions(+), 64 deletions(-)
+
+diff --git a/mythtv/libs/libmythui/mythmainwindow.cpp b/mythtv/libs/libmythui/mythmainwindow.cpp
+index c765279..226454a 100644
+--- a/mythtv/libs/libmythui/mythmainwindow.cpp
++++ b/mythtv/libs/libmythui/mythmainwindow.cpp
+@@ -25,6 +25,9 @@ using namespace std;
+ #include <QKeyEvent>
+ #include <QKeySequence>
+ #include <QSize>
++#include <QPair>
++#include <QMap>
++#include <QMutexLocker>
+ 
+ // Platform headers
+ #include "unistd.h"
+@@ -1765,67 +1768,107 @@ void MythMainWindow::BindKey(const QString &context, const QString &action,
+ void MythMainWindow::RegisterKey(const QString &context, const QString &action,
+                                  const QString &description, const QString &key)
+ {
+-    QString keybind = key;
+-
+-    MSqlQuery query(MSqlQuery::InitCon());
++    typedef QPair< QString,QString > key_t; // context, action
++    typedef QPair< QString,QString > val_t; // keybind, description
++    typedef QMap< key_t,val_t > cache_t;
++    static cache_t s_cache;
++    static QMutex s_mutex;
+ 
+-    if (d->m_useDB && query.isConnected())
++    if (s_cache.empty() && d->m_useDB)
+     {
+-        query.prepare("SELECT keylist, description FROM keybindings WHERE "
+-                      "context = :CONTEXT AND action = :ACTION AND "
+-                      "hostname = :HOSTNAME ;");
+-        query.bindValue(":CONTEXT", context);
+-        query.bindValue(":ACTION", action);
+-        query.bindValue(":HOSTNAME", GetMythDB()->GetHostName());
+-
+-        if (query.exec() && query.next())
++        MSqlQuery query(MSqlQuery::InitCon());
++        if (query.isConnected())
+         {
+-            keybind = query.value(0).toString();
+-            QString db_description = query.value(1).toString();
+-
+-            // Update keybinding description if changed
+-            if (db_description != description)
++            query.prepare("SELECT context, action, keylist, description "
++                          "FROM keybindings WHERE hostname = :HOSTNAME ;");
++            query.bindValue(":HOSTNAME", GetMythDB()->GetHostName());
++            if (query.exec())
+             {
+-                LOG(VB_GENERAL, LOG_NOTICE,
+-                    "Updating keybinding description...");
+-                query.prepare(
+-                    "UPDATE keybindings "
+-                    "SET description = :DESCRIPTION "
+-                    "WHERE context   = :CONTEXT AND "
+-                    "      action    = :ACTION  AND "
+-                    "      hostname  = :HOSTNAME");
+-
+-                query.bindValue(":DESCRIPTION", description);
+-                query.bindValue(":CONTEXT",     context);
+-                query.bindValue(":ACTION",      action);
+-                query.bindValue(":HOSTNAME",    GetMythDB()->GetHostName());
+-
+-                if (!query.exec() && !(GetMythDB()->SuppressDBMessages()))
++                QMutexLocker locker(&s_mutex);
++                while (query.next())
+                 {
+-                    MythDB::DBError("Update Keybinding", query);
++                    key_t k(query.value(0).toString(), query.value(1).toString());
++                    val_t v(query.value(2).toString(), query.value(3).toString());
++                    s_cache[k] = v;
+                 }
+             }
++            else if (!GetMythDB()->SuppressDBMessages())
++                MythDB::DBError("RegisterKey", query);
+         }
+-        else
++    }
++
++    QString keybind = key;
++    QString db_description;
++    bool bFound = false;
++    {
++        QMutexLocker locker(&s_mutex);
++        cache_t::const_iterator it = s_cache.find(key_t(context, action));
++        if (it != s_cache.end())
+         {
+-            QString inskey = keybind;
+-
+-            query.prepare("INSERT INTO keybindings (context, action, "
+-                          "description, keylist, hostname) VALUES "
+-                          "( :CONTEXT, :ACTION, :DESCRIPTION, :KEYLIST, "
+-                          ":HOSTNAME );");
+-            query.bindValue(":CONTEXT", context);
+-            query.bindValue(":ACTION", action);
++            keybind = it->first;
++            db_description = it->second;
++            bFound = true;
++        }
++    }
++
++    if (bFound)
++    {
++        // Update keybinding description if changed
++        if (db_description != description && d->m_useDB)
++        {
++            LOG(VB_GENERAL, LOG_NOTICE, "Updating keybinding description...");
++
++            MSqlQuery query(MSqlQuery::InitCon());
++
++            query.prepare(
++                "UPDATE keybindings "
++                "SET description = :DESCRIPTION "
++                "WHERE context   = :CONTEXT AND "
++                "      action    = :ACTION  AND "
++                "      hostname  = :HOSTNAME");
++
+             query.bindValue(":DESCRIPTION", description);
+-            query.bindValue(":KEYLIST", inskey);
+-            query.bindValue(":HOSTNAME", GetMythDB()->GetHostName());
++            query.bindValue(":CONTEXT",     context);
++            query.bindValue(":ACTION",      action);
++            query.bindValue(":HOSTNAME",    GetMythDB()->GetHostName());
+ 
+             if (!query.exec() && !(GetMythDB()->SuppressDBMessages()))
+             {
+-                MythDB::DBError("Insert Keybinding", query);
++                MythDB::DBError("Update Keybinding", query);
+             }
+         }
+     }
++    else if (d->m_useDB)
++    {
++        LOG(VB_GENERAL, LOG_NOTICE, QString("Add keybinding %1::%2 = %3")
++            .arg(context).arg(action).arg(keybind) );
++
++        MSqlQuery query(MSqlQuery::InitCon());
++
++        QString inskey = keybind;
++
++        query.prepare("INSERT INTO keybindings (context, action, "
++                      "description, keylist, hostname) VALUES "
++                      "( :CONTEXT, :ACTION, :DESCRIPTION, :KEYLIST, "
++                      ":HOSTNAME );");
++        query.bindValue(":CONTEXT", context);
++        query.bindValue(":ACTION", action);
++        query.bindValue(":DESCRIPTION", description);
++        query.bindValue(":KEYLIST", inskey);
++        query.bindValue(":HOSTNAME", GetMythDB()->GetHostName());
++
++        if (!query.exec() && !(GetMythDB()->SuppressDBMessages()))
++        {
++            MythDB::DBError("Insert Keybinding", query);
++        }
++        else
++        {
++            QMutexLocker locker(&s_mutex);
++            key_t k(context, action);
++            val_t v(keybind, description);
++            s_cache[k] = v;
++        }
++    }
+ 
+     BindKey(context, action, keybind);
+     d->actionText[context][action] = description;
+@@ -1930,35 +1973,75 @@ void MythMainWindow::RegisterJump(const QString &destination,
+                                   const QString &key, void (*callback)(void),
+                                   bool exittomain, QString localAction)
+ {
+-    QString keybind = key;
++    typedef QPair< QString,QString > val_t; // keylist, description
++    typedef QMap< QString,val_t > cache_t; // destination -> keylist, description
++    static cache_t s_cache;
++    static QMutex s_mutex;
+ 
+-    MSqlQuery query(MSqlQuery::InitCon());
+-    if (query.isConnected())
++    if (s_cache.empty() && d->m_useDB)
+     {
+-        query.prepare("SELECT keylist FROM jumppoints WHERE "
+-                      "destination = :DEST and hostname = :HOST ;");
+-        query.bindValue(":DEST", destination);
+-        query.bindValue(":HOST", GetMythDB()->GetHostName());
+-
+-        if (query.exec() && query.next())
++        MSqlQuery query(MSqlQuery::InitCon());
++        if (query.isConnected())
+         {
+-            keybind = query.value(0).toString();
++            query.prepare("SELECT destination, keylist, description "
++                          "FROM jumppoints WHERE hostname = :HOSTNAME ;");
++            query.bindValue(":HOSTNAME", GetMythDB()->GetHostName());
++            if (query.exec())
++            {
++                QMutexLocker locker(&s_mutex);
++                while (query.next())
++                {
++                    val_t v(query.value(1).toString(), query.value(2).toString());
++                    s_cache.insert(query.value(0).toString(), v);
++                }
++            }
++            else if (!GetMythDB()->SuppressDBMessages())
++                MythDB::DBError("RegisterJump", query);
+         }
+-        else
++    }
++
++    QString keybind = key;
++    bool bFound = false;
++    {
++        QMutexLocker locker(&s_mutex);
++        cache_t::const_iterator it = s_cache.find(destination);
++        if (it != s_cache.end())
+         {
+-            QString inskey = keybind;
++            keybind = it->first;
++            bFound = true;
++        }
++    }
+ 
+-            query.prepare("INSERT INTO jumppoints (destination, description, "
+-                          "keylist, hostname) VALUES ( :DEST, :DESC, :KEYLIST, "
+-                          ":HOST );");
++    if (!bFound)
++    {
++        MSqlQuery query(MSqlQuery::InitCon());
++        if (query.isConnected())
++        {
++            query.prepare("SELECT keylist FROM jumppoints WHERE "
++                          "destination = :DEST and hostname = :HOST ;");
+             query.bindValue(":DEST", destination);
+-            query.bindValue(":DESC", description);
+-            query.bindValue(":KEYLIST", inskey);
+             query.bindValue(":HOST", GetMythDB()->GetHostName());
+ 
+-            if (!query.exec() || !query.isActive())
++            if (query.exec() && query.next())
+             {
+-                MythDB::DBError("Insert Jump Point", query);
++                keybind = query.value(0).toString();
++            }
++            else
++            {
++                QString inskey = keybind;
++
++                query.prepare("INSERT INTO jumppoints (destination, description, "
++                              "keylist, hostname) VALUES ( :DEST, :DESC, :KEYLIST, "
++                              ":HOST );");
++                query.bindValue(":DEST", destination);
++                query.bindValue(":DESC", description);
++                query.bindValue(":KEYLIST", inskey);
++                query.bindValue(":HOST", GetMythDB()->GetHostName());
++
++                if (!query.exec() || !query.isActive())
++                {
++                    MythDB::DBError("Insert Jump Point", query);
++                }
+             }
+         }
+     }
+-- 
+1.7.9.5
+
diff --git a/abs/core/mythtv/stable-29/mythtv/PKGBUILD b/abs/core/mythtv/stable-29/mythtv/PKGBUILD
index ce77213..3a8faed 100644
--- a/abs/core/mythtv/stable-29/mythtv/PKGBUILD
+++ b/abs/core/mythtv/stable-29/mythtv/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=mythtv
 pkgver=29
-pkgrel=7
+pkgrel=8
 commit_hash=`cat ../git_src/git_hash`
 pkgdesc="A Homebrew PVR project $commit_hash"
 arch=('i686' 'x86_64')
@@ -37,6 +37,7 @@ patches=(
          '0292-UPnP-Reduce-startup-latency-by-moving-blocking-code-to-own-thread.patch'
          '0294-0283-FE-Add-network-status-to-machine-status-dialog.patch'
          '0287-MythUiImage-Don-t-block-UI-when-exiting-screens.patch'
+         '0259-0117-UI-Provide-dbase-cache-for-RegisterKey-and-RegisterJ.patch'
          )
 
 optdepends=()
@@ -135,4 +136,5 @@ md5sums=('fb5a87c52a31168a0c8fdde72f27cc45'
          '1f0dbd44f8c1a89b86bb331086f58578'
          'abaef221b00690b329f4dca18676bcd6'
          '3cccbab70c7615bc47e51790e024d5bf'
+         '4b5f00a19006b915b7ee5ab7f861599a'
          '633cd853a89aeee5388daaad21ccec28')
diff --git a/abs/core/mythtv/stable-29/mythweb/PKGBUILD b/abs/core/mythtv/stable-29/mythweb/PKGBUILD
index d294694..25dd0d9 100644
--- a/abs/core/mythtv/stable-29/mythweb/PKGBUILD
+++ b/abs/core/mythtv/stable-29/mythweb/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=mythweb
 pkgver=29
-pkgrel=2
+pkgrel=3
 commit_hash=`cat ../git_src/git_hash_web`
 pkgdesc="Web interface for MythTV's backend, $commit_hash"
 arch=('i686' 'x86_64')
-- 
cgit v0.12