[mythtv] file checks in HandleQueryRecordings

Tony Lill ajlill at ajlc.waterloo.on.ca
Sat Nov 25 03:31:05 UTC 2006


Chris Pinkham <cpinkham at bc2va.org> writes:

> * On Fri Nov 24, 2006 at 12:33:39PM -0500, Tony Lill wrote:
>> Something that I've done (besides commenting out the file checks) is
>> to let the frontend send an additional WHERE clause to the backend for
>> the QUERY_RECORDING message. It seems stupid to suck down info for a
>> thousand programs when you're going to ignore most of them. Between
>> the two changes, the time to display the results has dropped from a
>> minute to instantaneous, so, like, an easy 100x speedup. I can send
>> you the patch if you like, it's pretty simple and backwards compatible
>> (protocol wise). Don't know which change contributed more to the
>> speedup, though.
>
> I assume you're talking for things like the current recording group.
> With the recent cache additions, you may pay the penalty of retrieving
> all programs at the beginning, but switching between groups is fast
> because we don't reretrieve the list.  If we were to only retrieve the
> current recording group to begin with, then any switches would be slower
> unless that data was already in the cache.  So, it's a tradeoff.  It
> might be nice if the code was smart enough to only retrieve enough to
> fill out what you were currently looking at onscreen, although that
> trades off future speed for a quick start.  If you want to send it on,
> I'll at least take a look at it. :)

So how do you keep the list updated? If you're sitting looking at the
default recording group and a show starts or stops recording, or
another frontend deletes a program, you need to re-fetch, don't you?
Or is there some other mechanism for signalling the frontend that the
contents of this list has changed? 

Anyway, here's the patch. It's against the 0.20 branch

Index: libs/libmythtv/remoteutil.h
===================================================================
--- libs/libmythtv/remoteutil.h	(revision 11798)
+++ libs/libmythtv/remoteutil.h	(working copy)
@@ -19,7 +19,7 @@
     long long usedSpaceKB;
 };
 
-vector<ProgramInfo *> *RemoteGetRecordedList(bool deltype);
+vector<ProgramInfo *> *RemoteGetRecordedList(bool deltype, QString where);
 vector<FileSystemInfo> RemoteGetFreeSpace();
 bool RemoteGetLoad(float load[3]);
 bool RemoteGetUptime(time_t &uptime);
Index: libs/libmythtv/tv_play.cpp
===================================================================
--- libs/libmythtv/tv_play.cpp	(revision 11798)
+++ libs/libmythtv/tv_play.cpp	(working copy)
@@ -6144,8 +6144,9 @@
     // Build jumpMenu of recorded program titles
     ProgramInfo *p;
     progLists.clear();
+    QString whereClause = " and recorded.recgroup = \"" + playbackinfo->recgroup + "\"";
     vector<ProgramInfo *> *infoList;
-    infoList = RemoteGetRecordedList(false);
+    infoList = RemoteGetRecordedList(false, whereClause);
 
     bool LiveTVInAllPrograms = gContext->GetNumSetting("LiveTVInAllPrograms",0);
 
Index: libs/libmythtv/remoteutil.cpp
===================================================================
--- libs/libmythtv/remoteutil.cpp	(revision 11798)
+++ libs/libmythtv/remoteutil.cpp	(working copy)
@@ -6,13 +6,14 @@
 #include "mythcontext.h"
 #include "remoteencoder.h"
 
-vector<ProgramInfo *> *RemoteGetRecordedList(bool deltype)
+vector<ProgramInfo *> *RemoteGetRecordedList(bool deltype, QString whereClause)
 {
     QString str = "QUERY_RECORDINGS ";
     if (deltype)
         str += "Delete";
     else
         str += "Play";
+    str += whereClause;
 
     QStringList strlist = str;
 
Index: programs/mythfrontend/playbackbox.cpp
===================================================================
--- programs/mythfrontend/playbackbox.cpp	(revision 11798)
+++ programs/mythfrontend/playbackbox.cpp	(working copy)
@@ -1462,8 +1462,15 @@
 
     bool LiveTVInAllPrograms = gContext->GetNumSetting("LiveTVInAllPrograms",0);
 
+    QString whereClause = "";
+    if( recGroup != "All Programs" ) {
+      if(recGroupType[recGroup] == "category")
+	whereClause = " and recorded.category = \"" + recGroup + "\"";
+      else
+	whereClause = " and recorded.recgroup = \"" + recGroup + "\"";
+    }	
     vector<ProgramInfo *> *infoList;
-    infoList = RemoteGetRecordedList(listOrder == 0 || type == Delete);
+    infoList = RemoteGetRecordedList(listOrder == 0 || type == Delete, whereClause);
     if (infoList)
     {
         sortedList[""] = "";
Index: programs/mythbackend/mainserver.cpp
===================================================================
--- programs/mythbackend/mainserver.cpp	(revision 11798)
+++ programs/mythbackend/mainserver.cpp	(working copy)
@@ -351,10 +351,10 @@
 
     if (command == "QUERY_RECORDINGS")
     {
-        if (tokens.size() != 2)
+        if (tokens.size() < 2)
             VERBOSE(VB_IMPORTANT, "Bad QUERY_RECORDINGS query");
         else
-            HandleQueryRecordings(tokens[1], pbs);
+            HandleQueryRecordings(tokens, pbs);
     }
     else if (command == "QUERY_FREE_SPACE")
     {
@@ -996,11 +996,13 @@
     }
 }
 
-void MainServer::HandleQueryRecordings(QString type, PlaybackSock *pbs)
+void MainServer::HandleQueryRecordings(QStringList &tokens, PlaybackSock *pbs)
 {
+  QString type = tokens[1];
     MythSocket *pbssock = pbs->getSocket();
     bool islocal = pbs->isLocal();
     QString playbackhost = pbs->getHostname();
+    int i;
 
     QString fs_db_name = "";
 
@@ -1067,8 +1069,11 @@
         "  recorded.starttime = recordedprogram.starttime ) "
         "WHERE ( recorded.deletepending = 0 OR "
         "        DATE_ADD(recorded.lastmodified, INTERVAL 5 MINUTE) <= NOW() "
-        "      ) "
-        "ORDER BY recorded.starttime";
+      "      )";
+    for( i = 2; i < tokens.size(); i++ ) {
+      thequery += " "+tokens[i];
+    }
+        thequery += " ORDER BY recorded.starttime";
 
     if (type == "Delete")
         thequery += " DESC";
Index: programs/mythbackend/mainserver.h
===================================================================
--- programs/mythbackend/mainserver.h	(revision 11798)
+++ programs/mythbackend/mainserver.h	(working copy)
@@ -72,7 +72,7 @@
     void HandleDone(MythSocket *socket);
 
     void HandleIsActiveBackendQuery(QStringList &slist, PlaybackSock *pbs);
-    void HandleQueryRecordings(QString type, PlaybackSock *pbs);
+    void HandleQueryRecordings(QStringList &tokens, PlaybackSock *pbs);
     void HandleStopRecording(QStringList &slist, PlaybackSock *pbs);
     void DoHandleStopRecording(ProgramInfo *pginfo, PlaybackSock *pbs);
     void HandleDeleteRecording(QStringList &slist, PlaybackSock *pbs,


More information about the mythtv-dev mailing list