From e902a9bdfc61ae3dfdb0e421a576297b6929b71d Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Tue, 21 Jul 2020 18:06:39 +0300 Subject: [PATCH] [DATABASE] Check SQL boolean values with "IS TRUE" This way UNKNOWN (NULL) explicitly turns to FALSE when three-valued logic is reduced to binary. In pgsqlschema, however, use "IS FALSE" as boolean attributes in pg_index are non-nullable, there is no outer join and there's no clear preference for NULL reduction. Over-complicated constructions in TagCloud queries have been simplified, which should not affect their performance. Additionally, in TagCloud's lib/subscriptionspeopleselftagcloudsection.php a typing mistake in an equi-join of "profile_tag" and "profile_list" on "tagger" was fixed. That regression was introduced in f446db8e2ae9be8ae7b8489ddffcc04c6074b6f2 --- actions/peopletag.php | 86 ++++++++++--------- actions/selftag.php | 4 +- classes/Profile.php | 6 +- classes/Profile_tag.php | 4 +- classes/User_group.php | 7 +- lib/database/mysqlschema.php | 20 +++-- lib/database/pgsqlschema.php | 16 ++-- lib/profile/peopletagsbysubssection.php | 16 ++-- lib/util/mail.php | 4 +- .../ActivitySpam/scripts/silencespammer.php | 11 ++- .../subscriberspeopleselftagcloudsection.php | 73 ++++++++-------- .../lib/subscriberspeopletagcloudsection.php | 73 +++++++++------- ...subscriptionspeopleselftagcloudsection.php | 73 ++++++++-------- .../subscriptionspeopletagcloudsection.php | 73 +++++++++------- 14 files changed, 255 insertions(+), 211 deletions(-) diff --git a/actions/peopletag.php b/actions/peopletag.php index 323c3bfcb8..e47fb541e1 100644 --- a/actions/peopletag.php +++ b/actions/peopletag.php @@ -1,39 +1,32 @@ . + /** - * StatusNet, the distributed open-source microblogging tool - * * Lists by a user * - * PHP version 5 - * - * LICENCE: This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * PHP version 5 - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * * @category Personal - * @package StatusNet + * @package GNUsocial * @author Evan Prodromou * @author Zach Copley * @author Shashi Gowda * @copyright 2009 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); require_once INSTALLDIR . '/lib/profile/peopletaglist.php'; // cache 3 pages @@ -41,15 +34,15 @@ define('PEOPLETAG_CACHE_WINDOW', PEOPLETAGS_PER_PAGE*3 + 1); class PeopletagAction extends Action { - var $page = null; - var $tag = null; + public $page = null; + public $tag = null; - function isReadOnly($args) + public function isReadOnly($args) { return true; } - function title() + public function title() { if ($this->page == 1) { // TRANS: Title for list page. @@ -62,7 +55,7 @@ class PeopletagAction extends Action } } - function prepare(array $args = array()) + public function prepare(array $args = []) { parent::prepare($args); $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; @@ -84,19 +77,19 @@ class PeopletagAction extends Action return true; } - function handle() + public function handle() { parent::handle(); $this->showPage(); } - function showLocalNav() + public function showLocalNav() { $nav = new PublicGroupNav($this); $nav->show(); } - function showAnonymousMessage() + public function showAnonymousMessage() { $notice = // TRANS: Message for anonymous users on list page. @@ -106,13 +99,13 @@ class PeopletagAction extends Action '(http://en.wikipedia.org/wiki/Micro-blogging) service ' . 'based on the Free Software [StatusNet](http://status.net/) tool. ' . 'You can then easily keep track of what they ' . - 'are doing by subscribing to the list\'s timeline.' ); + "are doing by subscribing to the list's timeline."); $this->elementStart('div', array('id' => 'anon_notice')); $this->raw(common_markup_to_html($notice)); $this->elementEnd('div'); } - function showContent() + public function showContent() { $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE; $limit = PEOPLETAGS_PER_PAGE + 1; @@ -143,9 +136,15 @@ class PeopletagAction extends Action $ptags->find(); } } else { - $ptags->whereAdd('(profile_list.private = false OR (' . - ' profile_list.tagger =' . $user->id . - ' AND profile_list.private = true) )'); + $ptags->whereAdd(sprintf( + <<<'END' + ( + (profile_list.tagger = %d AND profile_list.private IS TRUE) + OR profile_list.private IS NOT TRUE + ) + END, + $user->getID() + )); $ptags->orderBy('profile_list.modified DESC'); $ptags->find(); @@ -154,11 +153,16 @@ class PeopletagAction extends Action $pl = new PeopletagList($ptags, $this); $cnt = $pl->show(); - $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE, - $this->page, 'peopletag', array('tag' => $this->tag)); + $this->pagination( + ($this->page > 1), + ($cnt > PEOPLETAGS_PER_PAGE), + $this->page, + 'peopletag', + ['tag' => $this->tag] + ); } - function showSections() + public function showSections() { } } diff --git a/actions/selftag.php b/actions/selftag.php index 1cf549b8ea..72c6e47d37 100644 --- a/actions/selftag.php +++ b/actions/selftag.php @@ -107,10 +107,10 @@ class SelftagAction extends Action $user = common_current_user(); if (empty($user)) { - $qry .= 'AND profile_list.private = false '; + $qry .= 'AND profile_list.private IS NOT TRUE '; } else { $qry .= 'AND (profile_list.tagger = ' . $user->id . - ' OR profile_list.private = false) '; + ' OR profile_list.private IS NOT TRUE) '; } $qry .= 'ORDER BY profile_tag.modified DESC ' . diff --git a/classes/Profile.php b/classes/Profile.php index a545c446c5..8239cfe5c4 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -504,13 +504,13 @@ class Profile extends Managed_DataObject if (!is_null($scoped)) { $qry .= sprintf( - 'AND ( profile_list.private = false ' . + 'AND ( profile_list.private IS NOT TRUE ' . 'OR ( profile_list.tagger = %d AND ' . - 'profile_list.private = TRUE ) )', + 'profile_list.private IS TRUE ) )', $scoped->getID() ); } else { - $qry .= 'AND profile_list.private = FALSE '; + $qry .= 'AND profile_list.private IS NOT TRUE '; } if ($since > 0) { diff --git a/classes/Profile_tag.php b/classes/Profile_tag.php index 70f57883ce..66a922de79 100644 --- a/classes/Profile_tag.php +++ b/classes/Profile_tag.php @@ -95,7 +95,7 @@ class Profile_tag extends Managed_DataObject $qry = sprintf($qry, $tagger, $tagged); if (!$include_priv) { - $qry .= ' AND profile_list.private = FALSE'; + $qry .= ' AND profile_list.private IS NOT TRUE'; } $profile_list->query($qry); @@ -121,7 +121,7 @@ class Profile_tag extends Managed_DataObject ); if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) { - $qry .= 'AND profile_list.private = FALSE'; + $qry .= 'AND profile_list.private IS NOT TRUE'; } $tags = array(); diff --git a/classes/User_group.php b/classes/User_group.php index a579d1126a..d10920da01 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -299,8 +299,11 @@ class User_group extends Managed_DataObject public function getAdmins($offset = null, $limit = null) { $admins = new Profile(); - $admins->joinAdd(array('id', 'group_member:profile_id')); - $admins->whereAdd('group_member.group_id = ' . $this->id . ' AND group_member.is_admin = true'); + $admins->joinAdd(['id', 'group_member:profile_id']); + $admins->whereAdd(sprintf( + 'group_member.group_id = %d AND group_member.is_admin IS TRUE', + $this->getID() + )); $admins->orderBy('group_member.modified ASC'); $admins->limit($offset, $limit); $admins->find(); diff --git a/lib/database/mysqlschema.php b/lib/database/mysqlschema.php index 2967fe019a..f86abf26b9 100644 --- a/lib/database/mysqlschema.php +++ b/lib/database/mysqlschema.php @@ -260,14 +260,20 @@ class MysqlSchema extends Schema */ public function fetchIndexInfo(string $table): array { - $query = 'SELECT INDEX_NAME AS `key_name`, INDEX_TYPE AS `key_type`, COLUMN_NAME AS `col` ' . - 'FROM INFORMATION_SCHEMA.STATISTICS ' . - 'WHERE TABLE_SCHEMA = \'%s\' AND TABLE_NAME = \'%s\' AND NON_UNIQUE = TRUE ' . - 'AND INDEX_NAME NOT IN (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME IS NOT NULL) ' . - 'ORDER BY SEQ_IN_INDEX'; $schema = $this->conn->dsn['database']; - $sql = sprintf($query, $schema, $table); - $data = $this->fetchQueryData($sql); + $data = $this->fetchQueryData( + <<fetchQueryData($sql); + return $this->fetchQueryData( + << %2$d ' . 'AND %1$s.smsemail IS NOT NULL ' . - 'AND %1$s.smsnotify = TRUE ' . + 'AND %1$s.smsnotify IS TRUE ' . // ... where either the user _is_ subscribed to the sender // (any of the "subscription" fields IS NOT NULL) // and wants to get SMS for all of this scribe's notices... - 'AND (subscription.sms = TRUE ' . + 'AND (subscription.sms IS TRUE ' . // ... or where the user was mentioned in // or replied-to with the notice: $repliesQry . diff --git a/plugins/ActivitySpam/scripts/silencespammer.php b/plugins/ActivitySpam/scripts/silencespammer.php index 18775c7696..b82622917c 100644 --- a/plugins/ActivitySpam/scripts/silencespammer.php +++ b/plugins/ActivitySpam/scripts/silencespammer.php @@ -83,9 +83,14 @@ function silencespammer($filter, $user, $minimum, $percent) $ss = new Spam_score(); - $ss->query(sprintf("SELECT count(*) as spam_count ". - "FROM notice join spam_score on notice.id = spam_score.notice_id ". - 'WHERE notice.profile_id = %d AND spam_score.is_spam = TRUE', $profile->id)); + $ss->query(sprintf( + <<<'END' + SELECT COUNT(*) AS spam_count + FROM notice INNER JOIN spam_score ON notice.id = spam_score.notice_id + WHERE notice.profile_id = %d AND spam_score.is_spam IS TRUE; + END, + $profile->getID() + )); while ($ss->fetch()) { $spam_count = $ss->spam_count; diff --git a/plugins/TagCloud/lib/subscriberspeopleselftagcloudsection.php b/plugins/TagCloud/lib/subscriberspeopleselftagcloudsection.php index ddbf389868..2af2d74d3b 100644 --- a/plugins/TagCloud/lib/subscriberspeopleselftagcloudsection.php +++ b/plugins/TagCloud/lib/subscriberspeopleselftagcloudsection.php @@ -1,58 +1,61 @@ . + /** - * StatusNet, the distributed open-source microblogging tool - * * Personal tag cloud section * - * PHP version 5 - * - * LICENCE: This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * * @category Widget - * @package StatusNet + * @package GNUsocial * @author Evan Prodromou * @copyright 2009 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Personal tag cloud section * - * @category Widget - * @package StatusNet - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @category Widget + * @package GNUsocial + * @author Evan Prodromou + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class SubscribersPeopleSelfTagCloudSection extends SubPeopleTagCloudSection { - function title() + public function title() { // TRANS: Title of personal tag cloud section. return _('People Tagcloud as self-tagged'); } - function query() { -// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged group by tag order by weight desc'; - - return 'select profile_tag.tag, count(profile_tag.tag) as weight from subscription left join (profile_tag, profile_list) on profile_list.tag = profile_tag.tag and profile_list.tagger = profile_tag.tagger and profile_tag.tagger = subscriber where subscribed=%d and subscribed != subscriber and profile_tag.tagger = tagged and profile_list.private = false and profile_tag.tag is not null group by profile_tag.tag order by weight desc'; - -// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscribed where subscriber=%d and subscribed != subscriber and tagger = tagged and tag is not null group by tag order by weight desc'; + public function query() + { + return <<<'END' + SELECT profile_tag.tag, COUNT(profile_tag.tag) AS weight + FROM profile_tag + INNER JOIN subscription AS sub + ON profile_tag.tagger = sub.subscriber + LEFT JOIN profile_list + ON profile_tag.tag = profile_list.tag + AND profile_tag.tagger = profile_list.tagger + WHERE profile_tag.tagger = profile_tag.tagged + AND profile_list.private IS NOT TRUE + AND sub.subscribed = %d AND sub.subscribed <> sub.subscriber + GROUP BY profile_tag.tag ORDER BY weight DESC; + END; } } diff --git a/plugins/TagCloud/lib/subscriberspeopletagcloudsection.php b/plugins/TagCloud/lib/subscriberspeopletagcloudsection.php index c3602a6b46..7b1ac362fe 100644 --- a/plugins/TagCloud/lib/subscriberspeopletagcloudsection.php +++ b/plugins/TagCloud/lib/subscriberspeopletagcloudsection.php @@ -1,60 +1,67 @@ . + /** - * StatusNet, the distributed open-source microblogging tool - * * Personal tag cloud section * - * PHP version 5 - * - * LICENCE: This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * * @category Widget - * @package StatusNet + * @package GNUsocial * @author Evan Prodromou * @copyright 2009 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Personal tag cloud section * - * @category Widget - * @package StatusNet - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @category Widget + * @package GNUsocial + * @author Evan Prodromou + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class SubscribersPeopleTagCloudSection extends SubPeopleTagCloudSection { - function title() + public function title() { // TRANS: Title of personal tag cloud section. return _('People Tagcloud as tagged'); } - function tagUrl($tag) { + public function tagUrl($tag) + { $nickname = $this->out->profile->nickname; return common_local_url('subscribers', array('nickname' => $nickname, 'tag' => $tag)); } - function query() { -// return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagged and subscribed=tagger where subscribed=%d and subscriber != subscribed group by tag order by weight desc'; - return 'select profile_tag.tag, count(profile_tag.tag) as weight from subscription left join (profile_tag, profile_list) on subscriber=profile_tag.tagged and subscribed=profile_tag.tagger and profile_tag.tagger = profile_list.tagger and profile_tag.tag = profile_list.tag where subscribed=%d and subscriber != subscribed and profile_list.private = false and profile_tag.tag is not null group by profile_tag.tag order by weight desc'; + public function query() + { + return <<<'END' + SELECT profile_tag.tag, COUNT(profile_tag.tag) AS weight + FROM profile_tag + INNER JOIN subscription AS sub + ON profile_tag.tagged = sub.subscriber + AND profile_tag.tagger = sub.subscribed + LEFT JOIN profile_list + ON profile_tag.tagger = profile_list.tagger + AND profile_tag.tag = profile_list.tag + WHERE profile_list.private IS NOT TRUE + AND sub.subscribed = %d AND sub.subscriber <> sub.subscribed + GROUP BY profile_tag.tag ORDER BY weight DESC; + END; } } diff --git a/plugins/TagCloud/lib/subscriptionspeopleselftagcloudsection.php b/plugins/TagCloud/lib/subscriptionspeopleselftagcloudsection.php index 7334234fc6..79cee1fe25 100644 --- a/plugins/TagCloud/lib/subscriptionspeopleselftagcloudsection.php +++ b/plugins/TagCloud/lib/subscriptionspeopleselftagcloudsection.php @@ -1,58 +1,61 @@ . + /** - * StatusNet, the distributed open-source microblogging tool - * * Personal tag cloud section * - * PHP version 5 - * - * LICENCE: This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * * @category Widget - * @package StatusNet + * @package GNUsocial * @author Evan Prodromou * @copyright 2009 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Personal tag cloud section * - * @category Widget - * @package StatusNet - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @category Widget + * @package GNUsocial + * @author Evan Prodromou + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class SubscriptionsPeopleSelfTagCloudSection extends SubPeopleTagCloudSection { - function title() + public function title() { // TRANS: Title of personal tag cloud section. return _('People Tagcloud as self-tagged'); } - function query() { -// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscriber != subscribed and tagger = tagged group by tag order by weight desc'; - - return 'select profile_tag.tag, count(profile_tag.tag) as weight from subscription left join (profile_tag, profile_list) on profile_tag.tagger = subscribed and profile_tag.tag = profile_list.tag and profile_tag.tagger = profile_tag.tagger where subscriber=%d and subscribed != subscriber and profile_tag.tagger = profile_tag.tagged and profile_list.private = false and profile_tag.tag is not null group by profile_tag.tag order by weight desc'; - -// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged and tag is not null group by tag order by weight desc'; + public function query() + { + return <<<'END' + SELECT profile_tag.tag, COUNT(profile_tag.tag) AS weight + FROM profile_tag + INNER JOIN subscription AS sub + ON profile_tag.tagger = sub.subscribed + LEFT JOIN profile_list + ON profile_tag.tag = profile_list.tag + AND profile_tag.tagger = profile_list.tagger + WHERE profile_tag.tagger = profile_tag.tagged + AND profile_list.private IS NOT TRUE + AND sub.subscriber = %d AND sub.subscribed <> sub.subscriber + GROUP BY profile_tag.tag ORDER BY weight DESC; + END; } } diff --git a/plugins/TagCloud/lib/subscriptionspeopletagcloudsection.php b/plugins/TagCloud/lib/subscriptionspeopletagcloudsection.php index e1016404c1..78211a0508 100644 --- a/plugins/TagCloud/lib/subscriptionspeopletagcloudsection.php +++ b/plugins/TagCloud/lib/subscriptionspeopletagcloudsection.php @@ -1,60 +1,67 @@ . + /** - * StatusNet, the distributed open-source microblogging tool - * * Personal tag cloud section * - * PHP version 5 - * - * LICENCE: This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * * @category Widget - * @package StatusNet + * @package GNUsocial * @author Evan Prodromou * @copyright 2009 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Personal tag cloud section * - * @category Widget - * @package StatusNet - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @category Widget + * @package GNUsocial + * @author Evan Prodromou + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class SubscriptionsPeopleTagCloudSection extends SubPeopleTagCloudSection { - function title() + public function title() { // TRANS: Title of personal tag cloud section. return _('People Tagcloud as tagged'); } - function tagUrl($tag) { + public function tagUrl($tag) + { $nickname = $this->out->profile->nickname; return common_local_url('subscriptions', array('nickname' => $nickname, 'tag' => $tag)); } - function query() { -// return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagger and subscribed=tagged where subscriber=%d and subscriber != subscribed group by tag order by weight desc'; - return 'select profile_tag.tag, count(profile_tag.tag) as weight from subscription left join (profile_tag, profile_list) on subscriber=profile_tag.tagger and subscribed=tagged and profile_tag.tag = profile_list.tag and profile_tag.tagger = profile_list.tagger where subscriber=%d and subscriber != subscribed and profile_list.private = false and profile_tag.tag is not null group by profile_tag.tag order by weight desc'; + public function query() + { + return <<<'END' + SELECT profile_tag.tag, COUNT(profile_tag.tag) AS weight + FROM profile_tag + INNER JOIN subscription AS sub + ON profile_tag.tagger = sub.subscriber + AND profile_tag.tagged = sub.subscribed + LEFT JOIN profile_list + ON profile_tag.tag = profile_list.tag + AND profile_tag.tagger = profile_list.tagger + WHERE profile_list.private IS NOT TRUE + AND sub.subscriber = %d AND sub.subscriber <> sub.subscribed + GROUP BY profile_tag.tag ORDER BY weight DESC; + END; } }