More replaced "q" calls
This commit is contained in:
parent
fcb018ebdd
commit
3972fe62fe
|
@ -3915,13 +3915,13 @@ function api_direct_messages_box($type, $box, $verbose)
|
|||
$sql_extra .= " AND `contact`.`nick` = '" . DBA::escape($screen_name). "'";
|
||||
}
|
||||
|
||||
$r = q(
|
||||
"SELECT `mail`.*, `contact`.`nurl` AS `contact-url` FROM `mail`,`contact` WHERE `mail`.`contact-id` = `contact`.`id` AND `mail`.`uid`=%d AND $sql_extra AND `mail`.`id` > %d ORDER BY `mail`.`id` DESC LIMIT %d,%d",
|
||||
intval(api_user()),
|
||||
intval($since_id),
|
||||
intval($start),
|
||||
intval($count)
|
||||
);
|
||||
$r = DBA::toArray(DBA::p(
|
||||
"SELECT `mail`.*, `contact`.`nurl` AS `contact-url` FROM `mail`,`contact` WHERE `mail`.`contact-id` = `contact`.`id` AND `mail`.`uid` = ? AND $sql_extra AND `mail`.`id` > ? ORDER BY `mail`.`id` DESC LIMIT ?,?",
|
||||
api_user(),
|
||||
$since_id,
|
||||
$start,
|
||||
$count
|
||||
));
|
||||
if ($verbose == "true" && !DBA::isResult($r)) {
|
||||
$answer = ['result' => 'error', 'message' => 'no mails available'];
|
||||
return api_format_data("direct_messages_all", $type, ['$result' => $answer]);
|
||||
|
@ -4123,12 +4123,12 @@ function api_fr_photos_list($type)
|
|||
if (api_user() === false) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
$r = q(
|
||||
$r = DBA::toArray(DBA::p(
|
||||
"SELECT `resource-id`, MAX(scale) AS `scale`, `album`, `filename`, `type`, MAX(`created`) AS `created`,
|
||||
MAX(`edited`) AS `edited`, MAX(`desc`) AS `desc` FROM `photo`
|
||||
WHERE `uid` = %d AND `album` != 'Contact Photos' GROUP BY `resource-id`, `album`, `filename`, `type`",
|
||||
intval(local_user())
|
||||
);
|
||||
WHERE `uid` = ? AND NOT `album` IN (?, ?) GROUP BY `resource-id`, `album`, `filename`, `type`",
|
||||
local_user(), Photo::CONTACT_PHOTOS, DI::l10n()->t(Photo::CONTACT_PHOTOS)
|
||||
));
|
||||
$typetoext = [
|
||||
'image/jpeg' => 'jpg',
|
||||
'image/png' => 'png',
|
||||
|
|
|
@ -45,12 +45,12 @@ function fbrowser_content(App $a)
|
|||
$sql_extra = "";
|
||||
$sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
|
||||
|
||||
if (DI::args()->getArgc()==2) {
|
||||
$photos = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
|
||||
intval(local_user()),
|
||||
DBA::escape(Photo::CONTACT_PHOTOS),
|
||||
DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
|
||||
);
|
||||
if (DI::args()->getArgc() == 2) {
|
||||
$photos = DBA::toArray(DBA::p("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = ? AND NOT `album` IN (?, ?)",
|
||||
local_user(),
|
||||
Photo::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(Photo::CONTACT_PHOTOS)
|
||||
));
|
||||
|
||||
$albums = array_column($photos, 'album');
|
||||
}
|
||||
|
@ -62,14 +62,14 @@ function fbrowser_content(App $a)
|
|||
$path[$album] = $album;
|
||||
}
|
||||
|
||||
$r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
|
||||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
|
||||
min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
|
||||
FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
|
||||
FROM `photo` WHERE `uid` = ? $sql_extra AND NOT `album` IN (?, ?)
|
||||
GROUP BY `resource-id` $sql_extra2",
|
||||
intval(local_user()),
|
||||
DBA::escape(Photo::CONTACT_PHOTOS),
|
||||
DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
|
||||
);
|
||||
local_user(),
|
||||
Photo::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(Photo::CONTACT_PHOTOS)
|
||||
));
|
||||
|
||||
function _map_files1($rr)
|
||||
{
|
||||
|
|
|
@ -213,12 +213,12 @@ function message_content(App $a)
|
|||
$o .= $header;
|
||||
|
||||
$total = 0;
|
||||
$r = q("SELECT count(*) AS `total`, ANY_VALUE(`created`) AS `created` FROM `mail`
|
||||
WHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `created` DESC",
|
||||
intval(local_user())
|
||||
$r = DBA::fetchFirst("SELECT count(*) AS `total`, ANY_VALUE(`created`) AS `created` FROM `mail`
|
||||
WHERE `mail`.`uid` = ? GROUP BY `parent-uri` ORDER BY `created` DESC",
|
||||
local_user()
|
||||
);
|
||||
if (DBA::isResult($r)) {
|
||||
$total = $r[0]['total'];
|
||||
$total = $r['total'];
|
||||
}
|
||||
|
||||
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
|
||||
|
|
|
@ -230,16 +230,16 @@ function photos_post(App $a)
|
|||
|
||||
// get the list of photos we are about to delete
|
||||
if ($visitor) {
|
||||
$r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
|
||||
intval($visitor),
|
||||
intval($page_owner_uid),
|
||||
DBA::escape($album)
|
||||
);
|
||||
$r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?",
|
||||
$visitor,
|
||||
$page_owner_uid,
|
||||
$album
|
||||
));
|
||||
} else {
|
||||
$r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
|
||||
intval(local_user()),
|
||||
DBA::escape($album)
|
||||
);
|
||||
$r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?",
|
||||
local_user(),
|
||||
$album
|
||||
));
|
||||
}
|
||||
|
||||
if (DBA::isResult($r)) {
|
||||
|
@ -977,11 +977,11 @@ function photos_content(App $a)
|
|||
$album = hex2bin($datum);
|
||||
|
||||
$total = 0;
|
||||
$r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
|
||||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ?
|
||||
AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
|
||||
intval($owner_uid),
|
||||
DBA::escape($album)
|
||||
);
|
||||
$owner_uid,
|
||||
$album
|
||||
));
|
||||
if (DBA::isResult($r)) {
|
||||
$total = count($r);
|
||||
}
|
||||
|
@ -996,16 +996,16 @@ function photos_content(App $a)
|
|||
$order = 'DESC';
|
||||
}
|
||||
|
||||
$r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
|
||||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
|
||||
ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
|
||||
ANY_VALUE(`created`) as `created`
|
||||
FROM `photo` WHERE `uid` = %d AND `album` = '%s'
|
||||
AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
|
||||
FROM `photo` WHERE `uid` = ? AND `album` = ?
|
||||
AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
|
||||
intval($owner_uid),
|
||||
DBA::escape($album),
|
||||
$pager->getStart(),
|
||||
$pager->getItemsPerPage()
|
||||
);
|
||||
));
|
||||
|
||||
if ($cmd === 'drop') {
|
||||
$drop_url = DI::args()->getQueryString();
|
||||
|
@ -1561,29 +1561,29 @@ function photos_content(App $a)
|
|||
// Default - show recent photos with upload link (if applicable)
|
||||
//$o = '';
|
||||
$total = 0;
|
||||
$r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
|
||||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND NOT `album` IN (?, ?)
|
||||
$sql_extra GROUP BY `resource-id`",
|
||||
intval($user['uid']),
|
||||
DBA::escape(Photo::CONTACT_PHOTOS),
|
||||
DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
|
||||
);
|
||||
$user['uid'],
|
||||
Photo::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(Photo::CONTACT_PHOTOS)
|
||||
));
|
||||
if (DBA::isResult($r)) {
|
||||
$total = count($r);
|
||||
}
|
||||
|
||||
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
|
||||
|
||||
$r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
|
||||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
|
||||
ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
|
||||
ANY_VALUE(`created`) AS `created` FROM `photo`
|
||||
WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
|
||||
$sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
|
||||
intval($user['uid']),
|
||||
DBA::escape(Photo::CONTACT_PHOTOS),
|
||||
DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
|
||||
WHERE `uid` = ? AND NOT `album` IN (?, ?)
|
||||
$sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT ? , ?",
|
||||
$user['uid'],
|
||||
Photo::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(Photo::CONTACT_PHOTOS),
|
||||
$pager->getStart(),
|
||||
$pager->getItemsPerPage()
|
||||
);
|
||||
));
|
||||
|
||||
$photos = [];
|
||||
if (DBA::isResult($r)) {
|
||||
|
|
34
mod/ping.php
34
mod/ping.php
|
@ -175,20 +175,20 @@ function ping_init(App $a)
|
|||
}
|
||||
}
|
||||
|
||||
$intros1 = q(
|
||||
$intros1 = DBA::toArray(DBA::p(
|
||||
"SELECT `intro`.`id`, `intro`.`datetime`,
|
||||
`fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo`
|
||||
FROM `intro` INNER JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
|
||||
WHERE `intro`.`uid` = %d AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`fid` != 0",
|
||||
intval(local_user())
|
||||
);
|
||||
$intros2 = q(
|
||||
WHERE `intro`.`uid` = ? AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`fid` != 0",
|
||||
local_user()
|
||||
));
|
||||
$intros2 = DBA::toArray(DBA::p(
|
||||
"SELECT `intro`.`id`, `intro`.`datetime`,
|
||||
`contact`.`name`, `contact`.`url`, `contact`.`photo`
|
||||
FROM `intro` INNER JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
|
||||
WHERE `intro`.`uid` = %d AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`contact-id` != 0 AND (`intro`.`fid` = 0 OR `intro`.`fid` IS NULL)",
|
||||
intval(local_user())
|
||||
);
|
||||
WHERE `intro`.`uid` = ? AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`contact-id` != 0 AND (`intro`.`fid` = 0 OR `intro`.`fid` IS NULL)",
|
||||
local_user()
|
||||
));
|
||||
|
||||
$intro_count = count($intros1) + count($intros2);
|
||||
$intros = $intros1 + $intros2;
|
||||
|
@ -397,17 +397,17 @@ function ping_get_notifications($uid)
|
|||
$quit = false;
|
||||
|
||||
do {
|
||||
$r = q(
|
||||
$r = DBA::toArray(DBA::p(
|
||||
"SELECT `notify`.*, `post`.`visible`, `post`.`deleted`
|
||||
FROM `notify` LEFT JOIN `post` ON `post`.`uri-id` = `notify`.`uri-id`
|
||||
WHERE `notify`.`uid` = %d AND `notify`.`msg` != ''
|
||||
AND NOT (`notify`.`type` IN (%d, %d))
|
||||
AND $seensql `notify`.`seen` ORDER BY `notify`.`date` $order LIMIT %d, 50",
|
||||
intval($uid),
|
||||
intval(Notification\Type::INTRO),
|
||||
intval(Notification\Type::MAIL),
|
||||
intval($offset)
|
||||
);
|
||||
WHERE `notify`.`uid` = ? AND `notify`.`msg` != ''
|
||||
AND NOT (`notify`.`type` IN (?, ?))
|
||||
AND $seensql `notify`.`seen` ORDER BY `notify`.`date` $order LIMIT ?, 50",
|
||||
$uid,
|
||||
Notification\Type::INTRO,
|
||||
Notification\Type::MAIL,
|
||||
$offset
|
||||
));
|
||||
|
||||
if (!$r && !$seen) {
|
||||
$seen = true;
|
||||
|
|
|
@ -651,23 +651,23 @@ class Photo
|
|||
if (!DI::config()->get("system", "no_count", false)) {
|
||||
/// @todo This query needs to be renewed. It is really slow
|
||||
// At this time we just store the data in the cache
|
||||
$albums = q("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created`
|
||||
$albums = DBA::toArray(DBA::p("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created`
|
||||
FROM `photo`
|
||||
WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra
|
||||
WHERE `uid` = ? AND `album` != ? AND `album` != ? $sql_extra
|
||||
GROUP BY `album` ORDER BY `created` DESC",
|
||||
intval($uid),
|
||||
DBA::escape(self::CONTACT_PHOTOS),
|
||||
DBA::escape(DI::l10n()->t(self::CONTACT_PHOTOS))
|
||||
);
|
||||
$uid,
|
||||
self::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(self::CONTACT_PHOTOS)
|
||||
));
|
||||
} else {
|
||||
// This query doesn't do the count and is much faster
|
||||
$albums = q("SELECT DISTINCT(`album`), '' AS `total`
|
||||
$albums = DBA::toArray(DBA::p("SELECT DISTINCT(`album`), '' AS `total`
|
||||
FROM `photo` USE INDEX (`uid_album_scale_created`)
|
||||
WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra",
|
||||
intval($uid),
|
||||
DBA::escape(self::CONTACT_PHOTOS),
|
||||
DBA::escape(DI::l10n()->t(self::CONTACT_PHOTOS))
|
||||
);
|
||||
WHERE `uid` = ? AND `album` != ? AND `album` != ? $sql_extra",
|
||||
$uid,
|
||||
self::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(self::CONTACT_PHOTOS)
|
||||
));
|
||||
}
|
||||
DI::cache()->set($key, $albums, Duration::DAY);
|
||||
}
|
||||
|
|
|
@ -164,25 +164,24 @@ class UserExport extends BaseSettings
|
|||
$table = $match[1];
|
||||
|
||||
$result = [];
|
||||
$r = q($query);
|
||||
if (DBA::isResult($r)) {
|
||||
foreach ($r as $rr) {
|
||||
foreach ($rr as $k => $v) {
|
||||
if (empty($dbStructure[$table]['fields'][$k])) {
|
||||
continue;
|
||||
}
|
||||
$rows = DBA::p($query);
|
||||
while ($row = DBA::fetch($rows)) {
|
||||
foreach ($row as $k => $v) {
|
||||
if (empty($dbStructure[$table]['fields'][$k])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($dbStructure[$table]['fields'][$k]['type']) {
|
||||
case 'datetime':
|
||||
$result[$k] = $v ?? DBA::NULL_DATETIME;
|
||||
break;
|
||||
default:
|
||||
$result[$k] = $v;
|
||||
break;
|
||||
}
|
||||
switch ($dbStructure[$table]['fields'][$k]['type']) {
|
||||
case 'datetime':
|
||||
$result[$k] = $v ?? DBA::NULL_DATETIME;
|
||||
break;
|
||||
default:
|
||||
$result[$k] = $v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
DBA::close($rows);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user