Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
pvr: optimize PersistGroupMembers for speed, by avoiding unneeded dat…
Browse files Browse the repository at this point in the history
…abase updates.

closes #81
  • Loading branch information
nemphys authored and opdenkamp committed May 4, 2011
1 parent 8f4eed5 commit a34880d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
31 changes: 23 additions & 8 deletions xbmc/pvr/PVRDatabase.cpp
Expand Up @@ -464,6 +464,12 @@ bool CPVRDatabase::RemoveChannelsFromGroup(const CPVRChannelGroup &group)
return DeleteValues("map_channelgroups_channels", strWhereClause);
}

bool CPVRDatabase::RemoveStaleChannelsFromGroup(const CPVRChannelGroup &group)
{
CStdString strWhereClause = FormatSQL("idGroup = %u AND iChannelNumber > %u", group.GroupID(), group.size());
return DeleteValues("map_channelgroups_channels", strWhereClause);
}

bool CPVRDatabase::DeleteChannelGroups(void)
{
CLog::Log(LOGDEBUG, "PVRDB - %s - deleting all channel groups from the database", __FUNCTION__);
Expand Down Expand Up @@ -600,27 +606,36 @@ bool CPVRDatabase::Persist(CPVRChannelGroup &group)

bool CPVRDatabase::PersistGroupMembers(CPVRChannelGroup &group)
{
bool bReturn = RemoveChannelsFromGroup(group);
bool bReturn = false;
bool bRemoveChannels = false;
CStdString strQuery;
CSingleLock lock(group.m_critSection);

if (bReturn && group.size() > 0)
if (group.size() > 0)
{
for (unsigned int iChannelPtr = 0; iChannelPtr < group.size(); iChannelPtr++)
{
PVRChannelGroupMember member = group.at(iChannelPtr);
strQuery = FormatSQL("REPLACE INTO map_channelgroups_channels ("
"idGroup, idChannel, iChannelNumber) "
"VALUES (%i, %i, %i);",
group.GroupID(), member.channel->ChannelID(), member.iChannelNumber);
QueueInsertQuery(strQuery);

CStdString strWhereClause = FormatSQL("idChannel = %u AND idGroup = %u AND iChannelNumber = %u",
member.channel->ChannelID(), group.GroupID(), member.iChannelNumber);

CStdString strValue = GetSingleValue("map_channelgroups_channels", "idChannel", strWhereClause);
if (strValue.IsEmpty()) {
strQuery = FormatSQL("REPLACE INTO map_channelgroups_channels ("
"idGroup, idChannel, iChannelNumber) "
"VALUES (%i, %i, %i);",
group.GroupID(), member.channel->ChannelID(), member.iChannelNumber);
QueueInsertQuery(strQuery);
}
}
lock.Leave();

This comment has been minimized.

Copy link
@nemphys

nemphys May 5, 2011

Author

Just noticed this: should the lock.leave() be here, or outside the if?

This comment has been minimized.

Copy link
@opdenkamp

opdenkamp May 5, 2011

Owner

should be here where it is now. after the queries have been queued and before they are committed.


bReturn = CommitInsertQueries();
bRemoveChannels = RemoveStaleChannelsFromGroup(group);
}

return bReturn;
return bReturn && bRemoveChannels;
}

/********** Client methods **********/
Expand Down
1 change: 1 addition & 0 deletions xbmc/pvr/PVRDatabase.h
Expand Up @@ -142,6 +142,7 @@ namespace PVR
//@{

bool RemoveChannelsFromGroup(const CPVRChannelGroup &group);
bool RemoveStaleChannelsFromGroup(const CPVRChannelGroup &group);

/*!
* @brief Remove all channel groups from the database
Expand Down

7 comments on commit a34880d

@nemphys
Copy link
Author

@nemphys nemphys commented on a34880d May 5, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if the if part is false (leave never executed), we leave the lock when the function exits, right (just want to get this straight)

@opdenkamp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, when the CSingleLock is destroyed

@nemphys
Copy link
Author

@nemphys nemphys commented on a34880d May 5, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanx. Just one more thing: I have noticed that if I leave XBMC open when I leave home in the morning and check back in the afternoon, it has become very laggy and needs to be restarted in order to work properly. Maybe there is a memory leak somewhere (?)
Btw, I know this is not the right place to post this, please instruct where to post the general (but private) talk (not to be filed as issues)

@opdenkamp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be a memory leak indeed.

you could contact me using github's messaging service, #xbmc-pvr on freenode or the xbmc forums. no reason to keep things like this private though, since others who have the same question can find the answer, or other (team xbmc) devs can comment on it.

@lkraav
Copy link

@lkraav lkraav commented on a34880d May 10, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nemphys: checking out .xbmc/temp/xbmc.log should give a clue what xbmc is doing when it's laggy. also monitor it's cpu usage with htop.

@nemphys
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, already doing that, of course, but it doesn't always give a hint about where the problem is, unless the specifc function is set to log things.

@lkraav
Copy link

@lkraav lkraav commented on a34880d May 10, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind, i only found out somewhat later that you were a coder :)

Please sign in to comment.