Skip to content

Commit

Permalink
[PVR] Fix for slow metadata updates from metaron
Browse files Browse the repository at this point in the history
  • Loading branch information
popcornmix committed Jan 1, 2015
1 parent a5bbb15 commit 7db79de
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
20 changes: 7 additions & 13 deletions xbmc/pvr/recordings/PVRRecording.cpp
Expand Up @@ -221,7 +221,7 @@ bool CPVRRecording::SetPlayCount(int count)
return true;
}

void CPVRRecording::UpdateMetadata(void)
void CPVRRecording::UpdateMetadata(CVideoDatabase &db)
{
if (m_bGotMetaData)
return;
Expand All @@ -231,20 +231,14 @@ void CPVRRecording::UpdateMetadata(void)

if (!supportsPlayCount || !supportsLastPlayed)
{
CVideoDatabase db;
if (db.Open())
if (!supportsPlayCount)
{
if (!supportsPlayCount)
{
CFileItem pFileItem(*this);
m_playCount = db.GetPlayCount(pFileItem);
}

if (!supportsLastPlayed)
db.GetResumeBookMark(m_strFileNameAndPath, m_resumePoint);

db.Close();
CFileItem pFileItem(*this);
m_playCount = db.GetPlayCount(pFileItem);
}

if (!supportsLastPlayed)
db.GetResumeBookMark(m_strFileNameAndPath, m_resumePoint);
}

m_bGotMetaData = true;
Expand Down
4 changes: 3 additions & 1 deletion xbmc/pvr/recordings/PVRRecording.h
Expand Up @@ -39,6 +39,8 @@
#include "video/VideoInfoTag.h"
#include "XBDateTime.h"

class CVideoDatabase;

namespace PVR
{
class CPVRRecording;
Expand Down Expand Up @@ -149,7 +151,7 @@ namespace PVR
* @brief Get the resume point and play count from the database if the
* client doesn't handle it itself.
*/
void UpdateMetadata(void);
void UpdateMetadata(CVideoDatabase &db);

/*!
* @brief Update this tag with the contents of the given tag.
Expand Down
27 changes: 23 additions & 4 deletions xbmc/pvr/recordings/PVRRecordings.cpp
Expand Up @@ -105,6 +105,9 @@ void CPVRRecordings::GetSubDirectories(const std::string &strBase, CFileItemList
std::string strUseBase = TrimSlashes(strBase);
std::set<CFileItemPtr> unwatchedFolders;

CVideoDatabase db;
bool dbLoaded = db.Open();

for (PVR_RECORDINGMAP_CITR it = m_recordings.begin(); it != m_recordings.end(); it++)
{
CPVRRecordingPtr current = it->second;
Expand All @@ -119,8 +122,9 @@ void CPVRRecordings::GetSubDirectories(const std::string &strBase, CFileItemList
strFilePath = StringUtils::Format("pvr://recordings/%s/%s/", strUseBase.c_str(), strCurrent.c_str());

CFileItemPtr pFileItem;
current->UpdateMetadata();

if (dbLoaded)
current->UpdateMetadata(db);

if (!results->Contains(strFilePath))
{
pFileItem.reset(new CFileItem(strCurrent, true));
Expand All @@ -143,6 +147,8 @@ void CPVRRecordings::GetSubDirectories(const std::string &strBase, CFileItemList
if (current->m_playCount == 0)
unwatchedFolders.insert(pFileItem);
}
if (dbLoaded)
db.Close();

// Remove the watched overlay from folders containing unwatched entries
for (std::set<CFileItemPtr>::iterator it = unwatchedFolders.begin(); it != unwatchedFolders.end(); ++it)
Expand Down Expand Up @@ -319,6 +325,9 @@ bool CPVRRecordings::GetDirectory(const std::string& strPath, CFileItemList &ite
if (m_bGroupItems)
GetSubDirectories(strDirectoryPath, &items);

CVideoDatabase db;
bool dbLoaded = db.Open();

// get all files of the currrent directory or recursively all files starting at the current directory if in flatten mode
for (PVR_RECORDINGMAP_CITR it = m_recordings.begin(); it != m_recordings.end(); it++)
{
Expand All @@ -328,7 +337,8 @@ bool CPVRRecordings::GetDirectory(const std::string& strPath, CFileItemList &ite
if (!IsDirectoryMember(strDirectoryPath, current->m_strDirectory))
continue;

current->UpdateMetadata();
if (dbLoaded)
current->UpdateMetadata(db);
CFileItemPtr pFileItem(new CFileItem(*current));
pFileItem->SetLabel2(current->RecordingTimeAsLocalTime().GetAsLocalizedDateTime(true, false));
pFileItem->m_dateTime = current->RecordingTimeAsLocalTime();
Expand All @@ -354,6 +364,8 @@ bool CPVRRecordings::GetDirectory(const std::string& strPath, CFileItemList &ite

items.Add(pFileItem);
}
if (dbLoaded)
db.Close();

return true;
}
Expand All @@ -364,10 +376,15 @@ bool CPVRRecordings::GetDirectory(const std::string& strPath, CFileItemList &ite
void CPVRRecordings::GetAll(CFileItemList &items)
{
CSingleLock lock(m_critSection);

CVideoDatabase db;
bool dbLoaded = db.Open();

for (PVR_RECORDINGMAP_CITR it = m_recordings.begin(); it != m_recordings.end(); it++)
{
CPVRRecordingPtr current = it->second;
current->UpdateMetadata();
if (dbLoaded)
current->UpdateMetadata(db);

CFileItemPtr pFileItem(new CFileItem(*current));
pFileItem->SetLabel2(current->RecordingTimeAsLocalTime().GetAsLocalizedDateTime(true, false));
Expand All @@ -377,6 +394,8 @@ void CPVRRecordings::GetAll(CFileItemList &items)

items.Add(pFileItem);
}
if (dbLoaded)
db.Close();
}

CFileItemPtr CPVRRecordings::GetById(unsigned int iId) const
Expand Down

0 comments on commit 7db79de

Please sign in to comment.