Ticket #5818: SWpatch_filemarkup_111008

File SWpatch_filemarkup_111008, 8.0 KB (added by simonwalls@…, 15 years ago)

Patch to 0.21-fixes SVN 17450 to improve efficiency of filemarkup table

Line 
1Index: libs/libmythtv/programinfo.cpp
2===================================================================
3--- libs/libmythtv/programinfo.cpp      (revision 17451)
4+++ libs/libmythtv/programinfo.cpp      (working copy)
5@@ -2505,10 +2505,23 @@
6     
7     if (isVideo)
8     {
9+        int videoid;
10+
11+        query.prepare("SELECT intid FROM videometadata"
12+                      " WHERE filename = :PATH ;");
13+        query.bindValue(":PATH", pathname);
14+
15+       if (query.exec() && query.isActive() && query.size() > 0)
16+       {
17+               while(query.next())
18+               videoid = query.value(1).toInt();
19+       }
20+        VERBOSE(VB_IMPORTANT, QString(LOC + "ClearMarkupMap: Video has id of '%1'")
21+                             .arg(videoid));
22         query.prepare("DELETE FROM filemarkup"
23-                      " WHERE filename = :PATH "
24+                      " WHERE filename = :ID "
25                       + comp + ";");
26-        query.bindValue(":PATH", pathname);
27+        query.bindValue(":ID", videoid);
28     }
29     else
30     {
31@@ -2567,9 +2580,22 @@
32 
33         if (isVideo)
34         {
35+            int videoid;
36+
37+            query.prepare("SELECT intid FROM videometadata"
38+                          " WHERE filename = :PATH ;");
39+            query.bindValue(":PATH", pathname);
40+
41+           if (query.exec() && query.isActive() && query.size() > 0)
42+           {
43+                   while(query.next())
44+                   videoid = query.value(1).toInt();
45+           }
46+            VERBOSE(VB_IMPORTANT, QString(LOC + "SetMarkupMap: Video has id of '%1'")
47+                             .arg(videoid));
48             query.prepare("INSERT INTO filemarkup (filename, mark, type)"
49-                          " VALUES ( :PATH , :MARK , :TYPE );");
50-            query.bindValue(":PATH", pathname);
51+                          " VALUES ( :ID , :MARK , :TYPE );");
52+            query.bindValue(":ID", videoid);
53         }
54         else
55         {
56@@ -2597,11 +2623,24 @@
57     
58     if (isVideo)
59     {
60+        int videoid;
61+
62+        query.prepare("SELECT intid FROM videometadata"
63+                      " WHERE filename = :PATH ;");
64+        query.bindValue(":PATH", pathname);
65+
66+       if (query.exec() && query.isActive() && query.size() > 0)
67+       {
68+               while(query.next())
69+               videoid = query.value(1).toInt();
70+       }
71+        VERBOSE(VB_IMPORTANT, QString(LOC + "GetMarkupMap: Video has id of '%1'")
72+                             .arg(videoid));
73         query.prepare("SELECT mark, type FROM filemarkup"
74-                      " WHERE filename = :PATH"
75+                      " WHERE filename = :ID"
76                       " AND type = :TYPE"
77                       " ORDER BY mark;");
78-        query.bindValue(":PATH", pathname);
79+        query.bindValue(":ID", videoid);
80     }
81     else
82     {
83@@ -2652,10 +2691,24 @@
84 
85     if (isVideo)
86     {
87-        query.prepare("SELECT mark, offset FROM filemarkup"
88-                      " WHERE filename = :PATH"
89-                      " AND type = :TYPE ;");
90+        int videoid;
91+
92+        query.prepare("SELECT intid FROM videometadata"
93+                      " WHERE filename = :PATH ;");
94         query.bindValue(":PATH", pathname);
95+
96+       if (query.exec() && query.isActive() && query.size() > 0)
97+       {
98+               while(query.next())
99+               videoid = query.value(1).toInt();
100+       }
101+        VERBOSE(VB_IMPORTANT, QString(LOC + "GetPositionMap: Video has id of '%1'")
102+                             .arg(videoid));
103+        query.prepare("SELECT mark, type FROM filemarkup"
104+                      " WHERE filename = :ID"
105+                      " AND type = :TYPE"
106+                      " ORDER BY mark;");
107+        query.bindValue(":ID", videoid);
108     }
109     else
110     {
111@@ -2681,10 +2734,23 @@
112   
113     if (isVideo)
114     {
115+        int videoid;
116+
117+        query.prepare("SELECT intid FROM videometadata"
118+                      " WHERE filename = :PATH ;");
119+        query.bindValue(":PATH", pathname);
120+
121+       if (query.exec() && query.isActive() && query.size() > 0)
122+       {
123+               while(query.next())
124+               videoid = query.value(1).toInt();
125+       }
126+        VERBOSE(VB_IMPORTANT, QString(LOC + "GetPositionMap: Video has id of '%1'")
127+                             .arg(videoid));
128         query.prepare("DELETE FROM filemarkup"
129-                      " WHERE filename = :PATH"
130+                      " WHERE filename = :ID"
131                       " AND type = :TYPE ;");
132-        query.bindValue(":PATH", pathname);
133+        query.bindValue(":ID", videoid);
134     }
135     else
136     {
137@@ -2705,6 +2771,8 @@
138 void ProgramInfo::SetPositionMap(frm_pos_map_t &posMap, int type,
139                                  long long min_frame, long long max_frame) const
140 {
141+    int videoid;
142+
143     QMap<long long, long long>::Iterator i;
144     MSqlQuery query(MSqlQuery::InitCon());
145     QString comp = "";
146@@ -2716,11 +2784,30 @@
147 
148     if (isVideo)
149     {
150+        query.prepare("SELECT intid FROM videometadata"
151+                      " WHERE filename = :PATH ;");
152+        query.bindValue(":PATH", pathname);
153+
154+       if (query.exec() && query.isActive() && query.size() > 0)
155+       {
156+               while(query.next())
157+               videoid = query.value(1).toInt();
158+       }
159+        VERBOSE(VB_IMPORTANT, QString(LOC + "SetPositionMap: Video has id of '%1'")
160+                             .arg(videoid));
161         query.prepare("DELETE FROM filemarkup"
162-                      " WHERE filename = :PATH"
163-                      " AND type = :TYPE"
164+                      " WHERE filename = :ID "
165+                      " AND type = :TYPE "
166                       + comp + ";");
167-        query.bindValue(":PATH", pathname);
168+        query.bindValue(":ID", videoid);
169+
170+        # Keep videoid for later
171+
172+        #query.prepare("DELETE FROM filemarkup"
173+        #              " WHERE filename = :PATH"
174+        #              " AND type = :TYPE"
175+        #              + comp + ";");
176+        #query.bindValue(":PATH", pathname);
177     }
178     else
179     {
180@@ -2759,8 +2846,8 @@
181             query.prepare("INSERT INTO filemarkup"
182                           " (filename, mark, type, offset)"
183                           " VALUES"
184-                          " ( :PATH , :MARK , :TYPE , :OFFSET );");
185-            query.bindValue(":PATH", pathname);
186+                          " ( :ID , :MARK , :TYPE , :OFFSET );");
187+            query.bindValue(":ID", videoid);
188         }
189         else
190         {       
191@@ -2794,11 +2881,22 @@
192 
193         if (isVideo)
194         {
195+            query.prepare("SELECT intid FROM videometadata"
196+                       " WHERE filename = :PATH ;");
197+            query.bindValue(":PATH", pathname);
198+       
199+           if (query.exec() && query.isActive() && query.size() > 0)
200+           {
201+                 while(query.next())
202+                 videoid = query.value(1).toInt();
203+            }
204+            VERBOSE(VB_IMPORTANT, QString(LOC + "SetPositionMapDelta: Video has id of '%1'")
205+                             .arg(videoid));
206             query.prepare("INSERT INTO filemarkup"
207                           " (filename, mark, type, offset)"
208                           " VALUES"
209-                          " ( :PATH , :MARK , :TYPE , :OFFSET );");
210-            query.bindValue(":PATH", pathname);
211+                          " ( :ID , :MARK , :TYPE , :OFFSET );");
212+            query.bindValue(":ID", videoid);
213         }
214         else
215         {
216@@ -3972,7 +4070,7 @@
217     MSqlQuery query(MSqlQuery::InitCon());
218 
219     query.prepare("SELECT commflagged, cutlist, autoexpire, "
220-                  "editing, bookmark, watched, preserve "
221+                  "editing, bookmark, watched, preserve, transcoded "
222                   "FROM recorded LEFT JOIN recordedprogram ON "
223                   "(recorded.chanid = recordedprogram.chanid AND "
224                   "recorded.progstart = recordedprogram.starttime) "
225@@ -3993,6 +4091,7 @@
226         flags |= (query.value(4).toInt() == 1) ? FL_BOOKMARK : 0;
227         flags |= (query.value(5).toInt() == 1) ? FL_WATCHED : 0;
228         flags |= (query.value(6).toInt() == 1) ? FL_PRESERVED : 0;
229+        flags |= (query.value(7).toInt() == 1) ? FL_TRANSCODED : 0;
230     }
231 
232     return flags;