[DATABASE] Fix remaining misuses of SQL's GROUP BY

This commit is contained in:
Alexei Sorokin
2020-08-10 19:29:04 +03:00
committed by Diogo Peralta Cordeiro
parent b0b10cf186
commit 03e69e8c31
5 changed files with 94 additions and 76 deletions

View File

@@ -41,11 +41,19 @@ class TopPostersSection extends ProfileSection
{
$limit = PROFILES_PER_SECTION;
$qry = 'SELECT profile.*, COUNT(*) AS value ' .
'FROM profile JOIN notice ON profile.id = notice.profile_id ' .
(common_config('public', 'localonly') ? 'WHERE is_local = 1 ' : '') .
'GROUP BY profile.id, nickname, fullname, profileurl, homepage, bio, location, profile.created, profile.modified ' .
'ORDER BY value DESC LIMIT ' . $limit;
$qry = sprintf(
<<<'END'
SELECT *
FROM profile INNER JOIN (
SELECT profile_id AS id, COUNT(profile_id) AS value
FROM notice
%1$sGROUP BY profile_id
) AS t1 USING (id)
ORDER BY value DESC LIMIT %2$d;
END,
(common_config('public', 'localonly') ? 'WHERE notice.is_local = 1 ' : ''),
$limit
);
$profile = Memcached_DataObject::cachedQuery('Profile', $qry, 6 * 3600);
return $profile;