Merge pull request #13835 from annando/no-any-value

"ANY_VALUE" is removed
This commit is contained in:
Hypolite Petovan 2024-01-15 14:16:12 -05:00 committed by GitHub
commit 8fc51cf63e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 79 deletions

View file

@ -215,14 +215,14 @@ function photos_post(App $a)
// get the list of photos we are about to delete // get the list of photos we are about to delete
if ($visitor) { if ($visitor) {
$r = DBA::toArray(DBA::p( $r = DBA::toArray(DBA::p(
"SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?", "SELECT distinct(`resource-id`) AS `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?",
$visitor, $visitor,
$page_owner_uid, $page_owner_uid,
$album $album
)); ));
} else { } else {
$r = DBA::toArray(DBA::p( $r = DBA::toArray(DBA::p(
"SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?", "SELECT distinct(`resource-id`) AS `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?",
DI::userSession()->getLocalUserId(), DI::userSession()->getLocalUserId(),
$album $album
)); ));
@ -762,7 +762,7 @@ function photos_content(App $a)
$total = 0; $total = 0;
$r = DBA::toArray(DBA::p( $r = DBA::toArray(DBA::p(
"SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ? "SELECT `resource-id`, MAX(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ?
AND `scale` <= 4 $sql_extra GROUP BY `resource-id`", AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
$owner_uid, $owner_uid,
$album $album
@ -782,9 +782,9 @@ function photos_content(App $a)
} }
$r = DBA::toArray(DBA::p( $r = DBA::toArray(DBA::p(
"SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, "SELECT `resource-id`, MIN(`id`) AS `id`, MIN(`filename`) AS `filename`,
ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`, MIN(`type`) AS `type`, MAX(`scale`) AS `scale`, MIN(`desc`) AS `desc`,
ANY_VALUE(`created`) as `created` MIN(`created`) AS `created`
FROM `photo` WHERE `uid` = ? AND `album` = ? FROM `photo` WHERE `uid` = ? AND `album` = ?
AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?", AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
intval($owner_uid), intval($owner_uid),
@ -1167,11 +1167,11 @@ function photos_content(App $a)
} }
if (!empty($conv_responses['like'][$link_item['uri']])) { if (!empty($conv_responses['like'][$link_item['uri']])) {
$like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']); $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id'], '', []);
} }
if (!empty($conv_responses['dislike'][$link_item['uri']])) { if (!empty($conv_responses['dislike'][$link_item['uri']])) {
$dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']); $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id'], '', []);
} }
if (($can_post || Security::canWriteToUserWall($owner_uid))) { if (($can_post || Security::canWriteToUserWall($owner_uid))) {

View file

@ -132,22 +132,6 @@ class DBA
return DI::dba()->connected(); return DI::dba()->connected();
} }
/**
* Replaces ANY_VALUE() function by MIN() function,
* if the database server does not support ANY_VALUE().
*
* Considerations for Standard SQL, or MySQL with ONLY_FULL_GROUP_BY (default since 5.7.5).
* ANY_VALUE() is available from MySQL 5.7.5 https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html
* A standard fall-back is to use MIN().
*
* @param string $sql An SQL string without the values
* @return string The input SQL string modified if necessary.
*/
public static function anyValueFallback(string $sql): string
{
return DI::dba()->anyValueFallback($sql);
}
/** /**
* beautifies the query - useful for "SHOW PROCESSLIST" * beautifies the query - useful for "SHOW PROCESSLIST"
* *

View file

@ -439,28 +439,6 @@ class Database
return $connected; return $connected;
} }
/**
* Replaces ANY_VALUE() function by MIN() function,
* if the database server does not support ANY_VALUE().
*
* Considerations for Standard SQL, or MySQL with ONLY_FULL_GROUP_BY (default since 5.7.5).
* ANY_VALUE() is available from MySQL 5.7.5 https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html
* A standard fall-back is to use MIN().
*
* @param string $sql An SQL string without the values
*
* @return string The input SQL string modified if necessary.
*/
public function anyValueFallback(string $sql): string
{
$server_info = $this->serverInfo();
if (version_compare($server_info, '5.7.5', '<') ||
(stripos($server_info, 'MariaDB') !== false)) {
$sql = str_ireplace('ANY_VALUE(', 'MIN(', $sql);
}
return $sql;
}
/** /**
* Replaces the ? placeholders with the parameters in the $args array * Replaces the ? placeholders with the parameters in the $args array
* *
@ -532,7 +510,6 @@ class Database
} }
$sql = DBA::cleanQuery($sql); $sql = DBA::cleanQuery($sql);
$sql = $this->anyValueFallback($sql);
$orig_sql = $sql; $orig_sql = $sql;
@ -1440,7 +1417,7 @@ class Database
private function escapeFields(array $fields, array $options): array private function escapeFields(array $fields, array $options): array
{ {
// In the case of a "GROUP BY" we have to add all the ORDER fields to the fieldlist. // In the case of a "GROUP BY" we have to add all the ORDER fields to the fieldlist.
// This needs to done to apply the "ANY_VALUE(...)" treatment from below to them. // This needs to done to apply the "MIN(...)" treatment from below to them.
// Otherwise MySQL would report errors. // Otherwise MySQL would report errors.
if (!empty($options['group_by']) && !empty($options['order'])) { if (!empty($options['group_by']) && !empty($options['order'])) {
foreach ($options['order'] as $key => $field) { foreach ($options['order'] as $key => $field) {
@ -1461,7 +1438,7 @@ class Database
$value = DBA::quoteIdentifier($field); $value = DBA::quoteIdentifier($field);
if (!empty($options['group_by']) && !in_array($field, $options['group_by'])) { if (!empty($options['group_by']) && !in_array($field, $options['group_by'])) {
$value = 'ANY_VALUE(' . $value . ') AS ' . $value; $value = 'MIN(' . $value . ') AS ' . $value;
} }
}); });

View file

@ -229,8 +229,8 @@ class Photo
return DBA::toArray( return DBA::toArray(
DBA::p( DBA::p(
"SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`, "SELECT `resource-id`, MIN(`id`) AS `id`, MIN(`filename`) AS `filename`, MIN(`type`) AS `type`,
min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created` min(`scale`) AS `hiq`, max(`scale`) AS `loq`, MIN(`desc`) AS `desc`, MIN(`created`) AS `created`
FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sqlExtra FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sqlExtra
GROUP BY `resource-id` $sqlExtra2", GROUP BY `resource-id` $sqlExtra2",
$values $values
@ -751,7 +751,7 @@ class Photo
if (!DI::config()->get('system', 'no_count', false)) { if (!DI::config()->get('system', 'no_count', false)) {
/// @todo This query needs to be renewed. It is really slow /// @todo This query needs to be renewed. It is really slow
// At this time we just store the data in the cache // At this time we just store the data in the cache
$albums = DBA::toArray(DBA::p("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`, MIN(`created`) AS `created`
FROM `photo` FROM `photo`
WHERE `uid` = ? AND `photo-type` IN (?, ?, ?) $sql_extra WHERE `uid` = ? AND `photo-type` IN (?, ?, ?) $sql_extra
GROUP BY `album` ORDER BY `created` DESC", GROUP BY `album` ORDER BY `created` DESC",

View file

@ -97,7 +97,7 @@ class Federation extends BaseAdmin
SUM(IFNULL(`local-posts`, 0) + IFNULL(`local-comments`, 0)) AS `posts`, SUM(IFNULL(`local-posts`, 0) + IFNULL(`local-comments`, 0)) AS `posts`,
SUM(IFNULL(`active-month-users`, `active-week-users`)) AS `month`, SUM(IFNULL(`active-month-users`, `active-week-users`)) AS `month`,
SUM(IFNULL(`active-halfyear-users`, `active-week-users`)) AS `halfyear`, `platform`, SUM(IFNULL(`active-halfyear-users`, `active-week-users`)) AS `halfyear`, `platform`,
ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version` MIN(`network`) AS `network`, MAX(`version`) AS `version`
FROM `gserver` WHERE NOT `failed` AND `platform` != ? AND `detection-method` != ? AND NOT `network` IN (?, ?) GROUP BY `platform`", FROM `gserver` WHERE NOT `failed` AND `platform` != ? AND `detection-method` != ? AND NOT `network` IN (?, ?) GROUP BY `platform`",
'', GServer::DETECT_MANUAL, Protocol::PHANTOM, Protocol::FEED); '', GServer::DETECT_MANUAL, Protocol::PHANTOM, Protocol::FEED);
while ($gserver = DBA::fetch($gservers)) { while ($gserver = DBA::fetch($gservers)) {

View file

@ -322,12 +322,12 @@ class Photos extends \Friendica\Module\BaseProfile
$photos = $this->database->toArray($this->database->p( $photos = $this->database->toArray($this->database->p(
"SELECT "SELECT
`resource-id`, `resource-id`,
ANY_VALUE(`id`) AS `id`, MIN(`id`) AS `id`,
ANY_VALUE(`filename`) AS `filename`, MIN(`filename`) AS `filename`,
ANY_VALUE(`type`) AS `type`, MIN(`type`) AS `type`,
ANY_VALUE(`album`) AS `album`, MIN(`album`) AS `album`,
max(`scale`) AS `scale`, MAX(`scale`) AS `scale`,
ANY_VALUE(`created`) AS `created` MIN(`created`) AS `created`
FROM `photo` FROM `photo`
WHERE `uid` = ? WHERE `uid` = ?
AND `photo-type` = ? AND `photo-type` = ?

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2024.03-dev\n" "Project-Id-Version: 2024.03-dev\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-14 07:50+0000\n" "POT-Creation-Date: 2024-01-15 16:52+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -953,7 +953,7 @@ msgstr ""
msgid "All pending post updates are done." msgid "All pending post updates are done."
msgstr "" msgstr ""
#: src/Console/User.php:158 src/Console/User.php:245 #: src/Console/User.php:158 src/Console/User.php:246
msgid "Enter user nickname: " msgid "Enter user nickname: "
msgstr "" msgstr ""
@ -980,44 +980,48 @@ msgstr ""
msgid "Password changed." msgid "Password changed."
msgstr "" msgstr ""
#: src/Console/User.php:237 #: src/Console/User.php:238
msgid "Enter user name: " msgid "Enter user name: "
msgstr "" msgstr ""
#: src/Console/User.php:253 #: src/Console/User.php:254
msgid "Enter user email address: " msgid "Enter user email address: "
msgstr "" msgstr ""
#: src/Console/User.php:261 #: src/Console/User.php:262
msgid "Enter a language (optional): " msgid "Enter a language (optional): "
msgstr "" msgstr ""
#: src/Console/User.php:286 #: src/Console/User.php:267
msgid "Enter URL of an image to use as avatar (optional): "
msgstr ""
#: src/Console/User.php:292
msgid "User is not pending." msgid "User is not pending."
msgstr "" msgstr ""
#: src/Console/User.php:318 #: src/Console/User.php:324
msgid "User has already been marked for deletion." msgid "User has already been marked for deletion."
msgstr "" msgstr ""
#: src/Console/User.php:323 #: src/Console/User.php:329
#, php-format #, php-format
msgid "Type \"yes\" to delete %s" msgid "Type \"yes\" to delete %s"
msgstr "" msgstr ""
#: src/Console/User.php:325 #: src/Console/User.php:331
msgid "Deletion aborted." msgid "Deletion aborted."
msgstr "" msgstr ""
#: src/Console/User.php:450 #: src/Console/User.php:456
msgid "Enter category: " msgid "Enter category: "
msgstr "" msgstr ""
#: src/Console/User.php:460 #: src/Console/User.php:466
msgid "Enter key: " msgid "Enter key: "
msgstr "" msgstr ""
#: src/Console/User.php:494 #: src/Console/User.php:500
msgid "Enter value: " msgid "Enter value: "
msgstr "" msgstr ""
@ -3785,7 +3789,7 @@ msgstr ""
msgid "Profile Photos" msgid "Profile Photos"
msgstr "" msgstr ""
#: src/Model/User.php:1582 #: src/Model/User.php:1584
#, php-format #, php-format
msgid "" msgid ""
"\n" "\n"
@ -3793,7 +3797,7 @@ msgid ""
"\t\t\tthe administrator of %2$s has set up an account for you." "\t\t\tthe administrator of %2$s has set up an account for you."
msgstr "" msgstr ""
#: src/Model/User.php:1585 #: src/Model/User.php:1587
#, php-format #, php-format
msgid "" msgid ""
"\n" "\n"
@ -3829,12 +3833,12 @@ msgid ""
"\t\tThank you and welcome to %4$s." "\t\tThank you and welcome to %4$s."
msgstr "" msgstr ""
#: src/Model/User.php:1617 src/Model/User.php:1723 #: src/Model/User.php:1619 src/Model/User.php:1725
#, php-format #, php-format
msgid "Registration details for %s" msgid "Registration details for %s"
msgstr "" msgstr ""
#: src/Model/User.php:1637 #: src/Model/User.php:1639
#, php-format #, php-format
msgid "" msgid ""
"\n" "\n"
@ -3850,12 +3854,12 @@ msgid ""
"\t\t" "\t\t"
msgstr "" msgstr ""
#: src/Model/User.php:1656 #: src/Model/User.php:1658
#, php-format #, php-format
msgid "Registration at %s" msgid "Registration at %s"
msgstr "" msgstr ""
#: src/Model/User.php:1680 #: src/Model/User.php:1682
#, php-format #, php-format
msgid "" msgid ""
"\n" "\n"
@ -3864,7 +3868,7 @@ msgid ""
"\t\t\t" "\t\t\t"
msgstr "" msgstr ""
#: src/Model/User.php:1688 #: src/Model/User.php:1690
#, php-format #, php-format
msgid "" msgid ""
"\n" "\n"
@ -3902,7 +3906,7 @@ msgid ""
"\t\t\tThank you and welcome to %2$s." "\t\t\tThank you and welcome to %2$s."
msgstr "" msgstr ""
#: src/Model/User.php:1750 #: src/Model/User.php:1752
msgid "" msgid ""
"User with delegates can't be removed, please remove delegate users first" "User with delegates can't be removed, please remove delegate users first"
msgstr "" msgstr ""