From: Philipp Holzer Date: Fri, 1 Mar 2019 16:15:34 +0000 (+0100) Subject: code lisibility & filter optimization X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ec2c84a4e90324ba2fe30eed955904b943349082;p=friendica.git code lisibility & filter optimization --- diff --git a/src/Content/ForumManager.php b/src/Content/ForumManager.php index b23a9e6924..e9dab41ef9 100644 --- a/src/Content/ForumManager.php +++ b/src/Content/ForumManager.php @@ -196,7 +196,7 @@ class ForumManager */ public static function countUnseenItems() { - $r = DBA::p( + $stmtContacts = DBA::p( "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item` INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id` WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen` @@ -208,6 +208,6 @@ class ForumManager intval(local_user()) ); - return DBA::toArray($r); + return DBA::toArray($stmtContacts); } } diff --git a/src/Core/NotificationsManager.php b/src/Core/NotificationsManager.php index d54492f3b0..4c6b932deb 100644 --- a/src/Core/NotificationsManager.php +++ b/src/Core/NotificationsManager.php @@ -36,7 +36,7 @@ class NotificationsManager extends BaseObject * - msg_plain: message as plain text string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - private function _set_extra($notes) + private function _set_extra(array $notes) { $rets = []; foreach ($notes as $n) { @@ -73,10 +73,10 @@ class NotificationsManager extends BaseObject $dbFilter = array_merge($filter, ['uid' => local_user()]); - $r = DBA::select('notify', [], $dbFilter, $order, $params); + $stmtNotifies = DBA::select('notify', [], $dbFilter, $order, $params); - if (DBA::isResult($r)) { - return $this->_set_extra($r); + if (DBA::isResult($stmtNotifies)) { + return $this->_set_extra(DBA::toArray($stmtNotifies)); } return false; @@ -91,9 +91,9 @@ class NotificationsManager extends BaseObject */ public function getByID($id) { - $r = DBA::selectFirst('notify', ['id' => $id, 'uid' => local_user()]); - if (DBA::isResult($r)) { - return $this->_set_extra($r)[0]; + $stmtNotify = DBA::selectFirst('notify', ['id' => $id, 'uid' => local_user()]); + if (DBA::isResult($stmtNotify)) { + return $this->_set_extra([$stmtNotify])[0]; } return null; } @@ -423,22 +423,21 @@ class NotificationsManager extends BaseObject $notifs = []; $sql_seen = ""; + $filter = ['uid' => local_user()]; if ($seen === 0) { - $filter = ['`uid` = ? AND NOT `seen`', local_user()]; - } else { - $filter = ['uid' => local_user()]; + $filter['seen'] = false; } $params = []; $params['limit'] = [$start, $limit]; - $r = DBA::select('notify', + $stmtNotifies = DBA::select('notify', ['id', 'url', 'photo', 'msg', 'date', 'seen', 'verb'], $filter, $params); - if (DBA::isResult($r)) { - $notifs = $this->formatNotifs(DBA::toArray($r), $ident); + if (DBA::isResult($stmtNotifies)) { + $notifs = $this->formatNotifs(DBA::toArray($stmtNotifies), $ident); } $arr = [ @@ -561,7 +560,7 @@ class NotificationsManager extends BaseObject } /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact - $r = DBA::p( + $stmtNotifies = DBA::p( "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`, `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`, @@ -578,8 +577,8 @@ class NotificationsManager extends BaseObject intval($start), intval($limit) ); - if (DBA::isResult($r)) { - $notifs = $this->formatIntros(DBA::toArray($r)); + if (DBA::isResult($stmtNotifies)) { + $notifs = $this->formatIntros(DBA::toArray($stmtNotifies)); } $arr = [ diff --git a/src/Core/UserImport.php b/src/Core/UserImport.php index 07119873d9..0a4223fecd 100644 --- a/src/Core/UserImport.php +++ b/src/Core/UserImport.php @@ -36,11 +36,11 @@ class UserImport */ private static function checkCols($table, &$arr) { - $r = DBStructure::getColumns($table); + $tableColumns = DBStructure::getColumns($table); $tcols = []; // get a plain array of column names - foreach ($r as $tcol) { + foreach ($tableColumns as $tcol) { $tcols[] = $tcol['Field']; } // remove inexistent columns diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 4732f8d707..abbac4e781 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -855,7 +855,7 @@ class DBStructure */ public static function getColumns($table) { - $r = DBA::p("SHOW COLUMNS FROM `" . $table . "`"); - return DBA::toArray($r); + $stmtColumns = DBA::p("SHOW COLUMNS FROM `" . $table . "`"); + return DBA::toArray($stmtColumns); } }