Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EPG] Misc cleanup & fix for async epg events not respecting epg lingertime #9997

Merged
merged 6 commits into from
Jun 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions xbmc/epg/Epg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ bool CEpg::UpdateEntry(const CEpgInfoTagPtr &tag, EPG_EVENT_STATE newState, std:
auto it = (eit == m_tags.end()) ? m_tags.find(tag->StartAsUTC()) : eit;
if (it == m_tags.end())
{
// not guranteed that deleted tag contains valid start time. search sequential.
// It is not guaranteed that the deleted tag contains valid start time. search sequential.
for (it = m_tags.begin(); it != m_tags.end(); ++it)
{
if (it->second->UniqueBroadcastID() == tag->UniqueBroadcastID())
Expand All @@ -412,11 +412,16 @@ bool CEpg::UpdateEntry(const CEpgInfoTagPtr &tag, EPG_EVENT_STATE newState, std:

if (it != m_tags.end())
{
it->second->ClearTimer();
m_tags.erase(it);
// Respect epg linger time.
const CDateTime cleanupTime(CDateTime::GetUTCDateTime() - CDateTimeSpan(0, g_advancedSettings.m_iEpgLingerTime / 60, g_advancedSettings.m_iEpgLingerTime % 60, 0));
if (it->second->EndAsUTC() < cleanupTime)
{
if (bUpdateDatabase)
m_deletedTags.insert(std::make_pair(it->second->UniqueBroadcastID(), it->second));

if (bUpdateDatabase)
m_deletedTags.insert(std::make_pair(infoTag->UniqueBroadcastID(), infoTag));
it->second->ClearTimer();
m_tags.erase(it);
}
}
else
{
Expand Down
15 changes: 8 additions & 7 deletions xbmc/epg/EpgContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ void CEpgContainer::LoadFromDB(void)
ShowProgressDialog(false);
}

m_database.DeleteOldEpgEntries();
const CDateTime cleanupTime(CDateTime::GetUTCDateTime() -
CDateTimeSpan(0, g_advancedSettings.m_iEpgLingerTime / 60, g_advancedSettings.m_iEpgLingerTime % 60, 0));
m_database.DeleteEpgEntries(cleanupTime);
m_database.Get(*this);

for (const auto &epgEntry : m_epgs)
Expand Down Expand Up @@ -316,7 +318,7 @@ void CEpgContainer::Process(void)
m_bIsInitialising = false;

/* clean up old entries */
if (!m_bStop && iNow >= m_iLastEpgCleanup)
if (!m_bStop && iNow >= m_iLastEpgCleanup + g_advancedSettings.m_iEpgCleanupInterval)
RemoveOldEntries();

/* check for pending manual EPG updates */
Expand Down Expand Up @@ -481,20 +483,19 @@ bool CEpgContainer::LoadSettings(void)

bool CEpgContainer::RemoveOldEntries(void)
{
CDateTime now = CDateTime::GetUTCDateTime() -
CDateTimeSpan(0, g_advancedSettings.m_iEpgLingerTime / 60, g_advancedSettings.m_iEpgLingerTime % 60, 0);
const CDateTime cleanupTime(CDateTime::GetUTCDateTime() -
CDateTimeSpan(0, g_advancedSettings.m_iEpgLingerTime / 60, g_advancedSettings.m_iEpgLingerTime % 60, 0));

/* call Cleanup() on all known EPG tables */
for (const auto &epgEntry : m_epgs)
epgEntry.second->Cleanup(now);
epgEntry.second->Cleanup(cleanupTime);

/* remove the old entries from the database */
if (!m_bIgnoreDbForClient && m_database.IsOpen())
m_database.DeleteOldEpgEntries();
m_database.DeleteEpgEntries(cleanupTime);

CSingleLock lock(m_critSection);
CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iLastEpgCleanup);
m_iLastEpgCleanup += g_advancedSettings.m_iEpgCleanupInterval;

return true;
}
Expand Down
10 changes: 4 additions & 6 deletions xbmc/epg/EpgDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,13 @@ bool CEpgDatabase::Delete(const CEpg &table)
return DeleteValues("epg", filter);
}

bool CEpgDatabase::DeleteOldEpgEntries(void)
bool CEpgDatabase::DeleteEpgEntries(const CDateTime &maxEndTime)
{
time_t iCleanupTime;
CDateTime cleanupTime = CDateTime::GetCurrentDateTime().GetAsUTCDateTime() -
CDateTimeSpan(0, g_advancedSettings.m_iEpgLingerTime / 60, g_advancedSettings.m_iEpgLingerTime % 60, 0);
cleanupTime.GetAsTime(iCleanupTime);
time_t iMaxEndTime;
maxEndTime.GetAsTime(iMaxEndTime);

Filter filter;
filter.AppendWhere(PrepareSQL("iEndTime < %u", iCleanupTime));
filter.AppendWhere(PrepareSQL("iEndTime < %u", iMaxEndTime));

return DeleteValues("epgtags", filter);
}
Expand Down
5 changes: 3 additions & 2 deletions xbmc/epg/EpgDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ namespace EPG
virtual bool Delete(const CEpg &table);

/*!
* @brief Erase all EPG entries older than 1 day.
* @brief Erase all EPG entries with an end time less than the given time.
* @param maxEndTime The maximum allowed end time.
* @return True if the entries were removed successfully, false otherwise.
*/
virtual bool DeleteOldEpgEntries(void);
virtual bool DeleteEpgEntries(const CDateTime &maxEndTime);

/*!
* @brief Remove a single EPG entry.
Expand Down
2 changes: 0 additions & 2 deletions xbmc/pvr/windows/GUIWindowPVRGuide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

#include "GUIWindowPVRGuide.h"

#define MAX_UPDATE_FREQUENCY 3000 // limit to maximum one update/refresh in x milliseconds

using namespace PVR;
using namespace EPG;

Expand Down