Browse Source

:bug: tweaking sql query for by-episode sort

tags/0.9.0
J 4 years ago
parent
commit
8744b4aa34

+ 4
- 3
plugins/cia-endpoints/includes/class.make-sortby.php View File

@@ -156,9 +156,10 @@ class Make_Sort_By extends WP_REST_Controller {
156 156
     public function by_episode( $request ) {
157 157
         $q = new WP_Query($this->make_args($request, null));
158 158
         global $wpdb;
159
+        
159 160
         $type = $q->query['post_type'] . 's';
161
+        
160 162
         // TODO: optimize this query
161
-        // $items = $q->get_posts();
162 163
         $items = $wpdb->get_results($wpdb->prepare(
163 164
             "SELECT DISTINCT wp_posts.*, 
164 165
                 header.post_title AS related_episode 
@@ -166,10 +167,10 @@ class Make_Sort_By extends WP_REST_Controller {
166 167
             ON (wp_p2p.p2p_from = wp_posts.ID OR wp_p2p.p2p_to = wp_posts.ID) 
167 168
             LEFT JOIN wp_posts AS header 
168 169
             ON header.ID = IF(wp_posts.ID = wp_p2p.p2p_to, wp_p2p.p2p_from, wp_p2p.p2p_to) 
169
-            WHERE wp_posts.post_type = %s AND wp_posts.post_status = 'publish' 
170
+            WHERE wp_posts.post_status = 'publish' 
170 171
                 AND (wp_p2p.p2p_type = %s OR wp_p2p.p2p_type = %s) 
171 172
             ORDER BY header.post_date DESC, related_episode, wp_posts.post_date DESC",
172
-            trim($type, 's'), $type . "_to_episodes" , "episodes_to_" . $type,
173
+            trim($type, 's'), $type . '_to_episodes' , 'episodes_to_' . $type,
173 174
         ));
174 175
         wp_reset_postdata();
175 176
 

+ 13
- 9
vue-theme/src/store/modules/arrangements.js View File

@@ -1,12 +1,16 @@
1 1
 import { sortTypes } from '../../utils/helpers'
2 2
 
3
-const _makeFlatpack = bySort => {
4
-    const flatPacked = []
5
-    Object.keys(bySort).forEach(sort => {
6
-        flatPacked.push({ slug: sort, title: sort, inbetween: true })
7
-        bySort[sort].forEach(post => flatPacked.push(post))
3
+const _insertInBetweens = bySort => {
4
+    const postListWithInBetweens = []
5
+    Object.keys(bySort).forEach(term => {
6
+        postListWithInBetweens.push({ 
7
+            slug: term,
8
+            title: term,
9
+            inbetween: true
10
+        })
11
+        bySort[term].forEach(post => postListWithInBetweens.push(post))
8 12
     })
9
-    return flatPacked
13
+    return postListWithInBetweens
10 14
 }
11 15
 
12 16
 const _arrangeByMaterial = postsList => {
@@ -19,7 +23,7 @@ const _arrangeByMaterial = postsList => {
19 23
             byMaterial[mat].push(post)
20 24
         })
21 25
     })
22
-    const flatPacked = _makeFlatpack(byMaterial)
26
+    const flatPacked = _insertInBetweens(byMaterial)
23 27
     return flatPacked
24 28
 }
25 29
 
@@ -32,7 +36,7 @@ const _arrangeByType = postsList => {
32 36
             byType[type].push(post)
33 37
         })
34 38
     })
35
-    const flatPacked = _makeFlatpack(byType)
39
+    const flatPacked = _insertInBetweens(byType)
36 40
     return flatPacked
37 41
 }
38 42
 
@@ -65,7 +69,7 @@ const _arrangeByEpisode = postsList => {
65 69
         if(!byEpisode[relatedEpisode]) byEpisode[relatedEpisode] = []
66 70
         byEpisode[relatedEpisode].push(post)
67 71
     })
68
-    const flatPacked = _makeFlatpack(byEpisode)
72
+    const flatPacked = _insertInBetweens(byEpisode)
69 73
     return flatPacked
70 74
 }
71 75
 

Loading…
Cancel
Save