Browse Source

code lisibility & filter optimization

pull/6923/head
Philipp Holzer 3 years ago
committed by Hypolite Petovan
parent
commit
ec2c84a4e9
  1. 4
      src/Content/ForumManager.php
  2. 31
      src/Core/NotificationsManager.php
  3. 4
      src/Core/UserImport.php
  4. 4
      src/Database/DBStructure.php

4
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);
}
}

31
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 = [

4
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

4
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);
}
}

Loading…
Cancel
Save