]> git.mxchange.org Git - friendica.git/commitdiff
Three more joins replaced with views
authorMichael <heluecht@pirati.ca>
Fri, 24 Apr 2020 20:39:14 +0000 (20:39 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 24 Apr 2020 20:39:14 +0000 (20:39 +0000)
src/Model/Profile.php
view/theme/vier/theme.php

index 4c877a9064d78ba7fe813d634a62893ddf808cd0..24db78a00acedc86c3aa947d3eb2554933fdaaa9 100644 (file)
@@ -887,30 +887,25 @@ class Profile
         */
        public static function searchProfiles($start = 0, $count = 100, $search = null)
        {
-               $publish = (DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1");
+               $publish = (DI::config()->get('system', 'publish_all') ? 'true' : "`publish` = 1");
                $total = 0;
 
                if (!empty($search)) {
                        $searchTerm = '%' . $search . '%';
-                       $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
-                               FROM `profile`
-                               LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                               WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
-                               AND ((`profile`.`name` LIKE ?) OR
-                               (`user`.`nickname` LIKE ?) OR
-                               (`profile`.`about` LIKE ?) OR
-                               (`profile`.`locality` LIKE ?) OR
-                               (`profile`.`region` LIKE ?) OR
-                               (`profile`.`country-name` LIKE ?) OR
-                               (`profile`.`pub_keywords` LIKE ?) OR
-                               (`profile`.`prv_keywords` LIKE ?))",
-                               $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
-                               $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm);
+                       $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `owner-view`
+                               WHERE $publish AND NOT `blocked` AND NOT `account_removed`
+                               AND ((`name` LIKE ?) OR
+                               (`nickname` LIKE ?) OR
+                               (`about` LIKE ?) OR
+                               (`locality` LIKE ?) OR
+                               (`region` LIKE ?) OR
+                               (`country-name` LIKE ?) OR
+                               (`pub_keywords` LIKE ?) OR
+                               (`prv_keywords` LIKE ?))",
+                               $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm);
                } else {
                        $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
-                               FROM `profile`
-                               LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                               WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`");
+                               FROM `owner-view` WHERE $publish AND NOT `blocked` AND NOT `account_removed`");
                }
 
                if (DBA::isResult($cnt)) {
@@ -925,35 +920,23 @@ class Profile
                        if (!empty($search)) {
                                $searchTerm = '%' . $search . '%';
 
-                               $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
-                       `contact`.`addr`, `contact`.`url` AS `profile_url`
-                       FROM `profile`
-                       LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                       LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
-                       WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
-                       AND ((`profile`.`name` LIKE ?) OR
-                               (`user`.`nickname` LIKE ?) OR
-                               (`profile`.`about` LIKE ?) OR
-                               (`profile`.`locality` LIKE ?) OR
-                               (`profile`.`region` LIKE ?) OR
-                               (`profile`.`country-name` LIKE ?) OR
-                               (`profile`.`pub_keywords` LIKE ?) OR
-                               (`profile`.`prv_keywords` LIKE ?))
-                       $order LIMIT ?,?",
+                               $profiles = DBA::p("SELECT * FROM `owner-view`
+                                       WHERE $publish AND NOT `blocked` AND NOT `account_removed`
+                                       AND ((`name` LIKE ?) OR
+                                               (`nickname` LIKE ?) OR
+                                               (`about` LIKE ?) OR
+                                               (`locality` LIKE ?) OR
+                                               (`region` LIKE ?) OR
+                                               (`country-name` LIKE ?) OR
+                                               (`pub_keywords` LIKE ?) OR
+                                               (`prv_keywords` LIKE ?))
+                                       $order LIMIT ?,?",
                                        $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
-                                       $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
                                        $start, $count
                                );
                        } else {
-                               $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
-                       `contact`.`addr`, `contact`.`url` AS `profile_url`
-                       FROM `profile`
-                       LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                       LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
-                       WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
-                       $order LIMIT ?,?",
-                                       $start, $count
-                               );
+                               $profiles = DBA::p("SELECT * FROM `owner-view`
+                                       WHERE $publish AND NOT `blocked` AND NOT `account_removed` $order LIMIT ?,?", $start, $count);
                        }
                }
 
index fcbb148dc7a3518c5eacf3ac194b143e1e089a85..cc3a668e6a8cd2f317de5c0815b2b4a41701e213 100644 (file)
@@ -140,29 +140,26 @@ function vier_community_info()
 
        // last 9 users
        if ($show_lastusers) {
-               $publish = (DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1");
-               $order = " ORDER BY `register_date` DESC ";
+               $condition = ['blocked' => false];
+               if (!DI::config()->get('system', 'publish_all')) {
+                       $condition['publish'] = true;
+               }
 
                $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
 
-               $r = q("SELECT `profile`.*, `user`.`nickname`
-                               FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                               WHERE $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
-                       0,
-                       9
-               );
+               $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
 
-               if (DBA::isResult($r)) {
+               if (DBA::isResult($profiles)) {
                        $aside['$lastusers_title'] = DI::l10n()->t('Last users');
                        $aside['$lastusers_items'] = [];
 
-                       foreach ($r as $rr) {
-                               $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['uid']);
+                       foreach ($profiles as $profile) {
+                               $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
                                $entry = Renderer::replaceMacros($tpl, [
-                                       '$id' => $rr['id'],
+                                       '$id' => $profile['id'],
                                        '$profile_link' => $profile_link,
-                                       '$photo' => DI::baseUrl()->remove($rr['thumb']),
-                                       '$alt_text' => $rr['name']]);
+                                       '$photo' => DI::baseUrl()->remove($profile['thumb']),
+                                       '$alt_text' => $profile['name']]);
                                $aside['$lastusers_items'][] = $entry;
                        }
                }