Skip to content

Commit

Permalink
[PVR] Fix EPG last scan time handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksooo committed Dec 22, 2020
1 parent 53f8b16 commit 91608d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
16 changes: 15 additions & 1 deletion xbmc/pvr/epg/Epg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ bool CPVREpg::Update(time_t start,
bool bGrabSuccess = true;
bool bUpdate = false;

if (!m_lastScanTime.IsValid())
{
database->GetLastEpgScanTime(m_iEpgID, &m_lastScanTime);

if (!m_lastScanTime.IsValid())
{
m_lastScanTime.SetFromUTCDateTime(time_t(0));
m_bUpdateLastScanTime = true;
}
}

/* clean up if needed */
Cleanup(iPastDays);

Expand Down Expand Up @@ -341,6 +352,9 @@ bool CPVREpg::QueueDeleteQueries(const std::shared_ptr<CPVREpgDatabase>& databas
// delete own epg db entry
database->QueueDeleteEpgQuery(*this);

// delete last scan time db entry for this epg
database->QueueDeleteLastEpgScanTimeQuery(*this);

// delete all tags for this epg from db
m_tags.QueueDelete();

Expand Down Expand Up @@ -518,7 +532,7 @@ bool CPVREpg::UpdatePending() const
bool CPVREpg::NeedsSave() const
{
CSingleLock lock(m_critSection);
return m_bChanged || m_tags.NeedsSave();
return m_bChanged || m_bUpdateLastScanTime || m_tags.NeedsSave();
}

bool CPVREpg::IsValid() const
Expand Down
20 changes: 20 additions & 0 deletions xbmc/pvr/epg/EpgDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,26 @@ bool CPVREpgDatabase::QueuePersistLastEpgScanTimeQuery(int iEpgId, const CDateTi
return QueueInsertQuery(strQuery);
}

bool CPVREpgDatabase::QueueDeleteLastEpgScanTimeQuery(const CPVREpg& table)
{
if (table.EpgID() <= 0)
{
CLog::LogF(LOGERROR, "Invalid EPG id: {}", table.EpgID());
return false;
}

Filter filter;

CSingleLock lock(m_critSection);
filter.AppendWhere(PrepareSQL("idEpg = %u", table.EpgID()));

std::string strQuery;
if (BuildSQL(PrepareSQL("DELETE FROM %s ", "lastepgscan"), filter, strQuery))
return QueueDeleteQuery(strQuery);

return false;
}

int CPVREpgDatabase::Persist(const CPVREpg& epg, bool bQueueWrite)
{
int iReturn = -1;
Expand Down
7 changes: 7 additions & 0 deletions xbmc/pvr/epg/EpgDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ namespace PVR
*/
bool QueuePersistLastEpgScanTimeQuery(int iEpgId, const CDateTime& lastScanTime);

/*!
* @brief Write the query to delete the last scan time for the given EPG to db query queue.
* @param iEpgId The table to delete the time for.
* @return True on success, false otherwise.
*/
bool QueueDeleteLastEpgScanTimeQuery(const CPVREpg& table);

/*!
* @brief Persist an EPG table. It's entries are not persisted.
* @param epg The table to persist.
Expand Down

0 comments on commit 91608d8

Please sign in to comment.