aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphunkyfish <phunkyfish@gmail.com>2020-11-11 17:20:44 +0000
committerGitHub <noreply@github.com>2020-11-11 17:20:44 +0000
commit842c81bce4b8aef2ffd0359ca65f22c8ecb17c1b (patch)
treeb18538b5466a8e0fd38955ce6a71baa5af527063
parentb5871f5c48df16f862930773bddbd36dc2e13dc5 (diff)
parent20b7c6353aa13934a7090445791bde713a59603d (diff)
Merge pull request #18750 from phunkyfish/bulk-commmit-pvr-v2
[pvr] bulk commit queries across the deletion of multiple epgs
-rw-r--r--xbmc/pvr/PVRDatabase.h2
-rw-r--r--xbmc/pvr/channels/PVRChannel.cpp2
-rw-r--r--xbmc/pvr/channels/PVRChannelGroupInternal.cpp22
-rw-r--r--xbmc/pvr/epg/EpgContainer.cpp19
-rw-r--r--xbmc/pvr/epg/EpgContainer.h4
-rw-r--r--xbmc/pvr/epg/EpgDatabase.h2
6 files changed, 38 insertions, 13 deletions
diff --git a/xbmc/pvr/PVRDatabase.h b/xbmc/pvr/PVRDatabase.h
index b2b73db319..f5d23db0a6 100644
--- a/xbmc/pvr/PVRDatabase.h
+++ b/xbmc/pvr/PVRDatabase.h
@@ -25,6 +25,8 @@ namespace PVR
/** The PVR database */
+ static constexpr int CHANNEL_COMMIT_QUERY_COUNT_LIMIT = 10000;
+
class CPVRDatabase : public CDatabase
{
public:
diff --git a/xbmc/pvr/channels/PVRChannel.cpp b/xbmc/pvr/channels/PVRChannel.cpp
index 271d1b336e..7798653929 100644
--- a/xbmc/pvr/channels/PVRChannel.cpp
+++ b/xbmc/pvr/channels/PVRChannel.cpp
@@ -111,7 +111,7 @@ bool CPVRChannel::QueueDelete()
const std::shared_ptr<CPVREpg> epg = GetEPG();
if (epg)
{
- CServiceBroker::GetPVRManager().EpgContainer().DeleteEpg(epg);
+ CServiceBroker::GetPVRManager().EpgContainer().QueueDeleteEpg(epg);
CSingleLock lock(m_critSection);
m_epg.reset();
diff --git a/xbmc/pvr/channels/PVRChannelGroupInternal.cpp b/xbmc/pvr/channels/PVRChannelGroupInternal.cpp
index 5b51c4ca2d..fe21c30975 100644
--- a/xbmc/pvr/channels/PVRChannelGroupInternal.cpp
+++ b/xbmc/pvr/channels/PVRChannelGroupInternal.cpp
@@ -17,6 +17,7 @@
#include "pvr/addons/PVRClients.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/epg/EpgContainer.h"
+#include "pvr/epg/EpgDatabase.h"
#include "utils/Variant.h"
#include "utils/log.h"
@@ -285,24 +286,39 @@ std::vector<std::shared_ptr<CPVRChannel>> CPVRChannelGroupInternal::RemoveDelete
bool channelsDeleted = false;
const std::shared_ptr<CPVRDatabase> database = CServiceBroker::GetPVRManager().GetTVDatabase();
- if (!database)
+ const std::shared_ptr<CPVREpgDatabase> epgDatabase =
+ CServiceBroker::GetPVRManager().EpgContainer().GetEpgDatabase();
+ if (!database || !epgDatabase)
{
- CLog::LogF(LOGERROR, "No TV database");
+ CLog::LogF(LOGERROR, "No TV or EPG database");
}
else
{
- // Note: We must lock the db the whole time, otherwise races may occur.
+ // Note: We must lock the dbs the whole time, otherwise races may occur.
database->Lock();
+ epgDatabase->Lock();
for (const auto& channel : removedChannels)
{
// since channel was not found in the internal group, it was deleted from the backend
channelsDeleted |= channel->QueueDelete();
+
+ size_t queryCount = epgDatabase->GetDeleteQueriesCount();
+ if (queryCount > EPG_COMMIT_QUERY_COUNT_LIMIT)
+ epgDatabase->CommitDeleteQueries();
+
+ queryCount = database->GetDeleteQueriesCount();
+ if (queryCount > CHANNEL_COMMIT_QUERY_COUNT_LIMIT)
+ database->CommitDeleteQueries();
}
if (channelsDeleted)
+ {
+ epgDatabase->CommitDeleteQueries();
database->CommitDeleteQueries();
+ }
+ epgDatabase->Unlock();
database->Unlock();
}
diff --git a/xbmc/pvr/epg/EpgContainer.cpp b/xbmc/pvr/epg/EpgContainer.cpp
index 00ca07e522..2ffac5b268 100644
--- a/xbmc/pvr/epg/EpgContainer.cpp
+++ b/xbmc/pvr/epg/EpgContainer.cpp
@@ -319,7 +319,7 @@ bool CPVREpgContainer::PersistAll(unsigned int iMaxTimeslice) const
bReturn &= epg->QueuePersistQuery(database);
size_t queryCount = database->GetInsertQueriesCount() + database->GetDeleteQueriesCount();
- if (queryCount > 10000)
+ if (queryCount > EPG_COMMIT_QUERY_COUNT_LIMIT)
{
CLog::LogFC(LOGDEBUG, LOGEPG, "EPG Container: committing {} queries in loop.",
queryCount);
@@ -626,7 +626,7 @@ bool CPVREpgContainer::RemoveOldEntries()
return true;
}
-bool CPVREpgContainer::DeleteEpg(const std::shared_ptr<CPVREpg>& epg)
+bool CPVREpgContainer::QueueDeleteEpg(const std::shared_ptr<CPVREpg>& epg)
{
if (!epg || epg->EpgID() < 0)
return false;
@@ -652,11 +652,7 @@ bool CPVREpgContainer::DeleteEpg(const std::shared_ptr<CPVREpg>& epg)
m_channelUidToEpgMap.erase(epgEntry1);
CLog::LogFC(LOGDEBUG, LOGEPG, "Deleting EPG table {} ({})", epg->Name(), epg->EpgID());
-
- database->Lock();
epgEntry->second->QueueDeleteQueries(database);
- database->CommitDeleteQueries();
- database->Unlock();
epgToDelete = epgEntry->second;
m_epgIdToEpgMap.erase(epgEntry);
@@ -759,8 +755,17 @@ bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
if (bShowProgress && !bOnlyPending)
progressHandler->DestroyProgress();
+ database->Lock();
for (const auto& epg : invalidTables)
- DeleteEpg(epg);
+ {
+ QueueDeleteEpg(epg);
+
+ size_t queryCount = database->GetDeleteQueriesCount();
+ if (queryCount > EPG_COMMIT_QUERY_COUNT_LIMIT)
+ database->CommitDeleteQueries();
+ }
+ database->CommitDeleteQueries();
+ database->Unlock();
if (bInterrupted)
{
diff --git a/xbmc/pvr/epg/EpgContainer.h b/xbmc/pvr/epg/EpgContainer.h
index edfc48c4e6..c997b963ce 100644
--- a/xbmc/pvr/epg/EpgContainer.h
+++ b/xbmc/pvr/epg/EpgContainer.h
@@ -86,11 +86,11 @@ namespace PVR
bool IsStarted() const;
/*!
- * @brief Delete an EPG table from this container.
+ * @brief Queue the deletion of an EPG table from this container.
* @param epg The table to delete.
* @return True on success, false otherwise.
*/
- bool DeleteEpg(const std::shared_ptr<CPVREpg>& epg);
+ bool QueueDeleteEpg(const std::shared_ptr<CPVREpg>& epg);
/*!
* @brief CEventStream callback for PVR events.
diff --git a/xbmc/pvr/epg/EpgDatabase.h b/xbmc/pvr/epg/EpgDatabase.h
index c9b28842fd..a0ab972d59 100644
--- a/xbmc/pvr/epg/EpgDatabase.h
+++ b/xbmc/pvr/epg/EpgDatabase.h
@@ -25,6 +25,8 @@ namespace PVR
/** The EPG database */
+ static constexpr int EPG_COMMIT_QUERY_COUNT_LIMIT = 10000;
+
class CPVREpgDatabase : public CDatabase, public std::enable_shared_from_this<CPVREpgDatabase>
{
public: