forked from GNUsocial/gnu-social
[DATABASE] Some query improvements
Make common_sql_weight employ standard SQL functions for the timestamp difference in seconds. Also replace UTC_TIMESTAMP in the MariaDB-specific part with CURRENT_TIMESTAMP as it is the only occurence and GNU social sets UTC as a default timezone. In a delete_orphan_files.php script simplify the main query considerably. In clean_profiles.php stop using COUNT as if it is ANY, that is unnecessary punishment for the database. Instead implement the anti-join with a left outer join. In Autocomplete and Activitypub_profile use joins instead of a WHERE OR anti-pattern for the semi-joins. In lib/ui/galleryaction.php replace a CROSS JOIN with an INNER JOIN. In actions/sup.php remove a redundant subquery: WHERE is applied before grouping either way.
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* StatusNet - a distributed open-source microblogging tool
|
||||
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social 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.
|
||||
//
|
||||
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @copyright 2008, 2009 StatusNet, Inc.
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
|
||||
define('INSTALLDIR', dirname(__DIR__));
|
||||
@@ -43,12 +45,13 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
|
||||
|
||||
print "Finding File entries that are not related to a Notice (or the notice has been deleted)...";
|
||||
$file = new File();
|
||||
$sql = 'SELECT file.* FROM file'.
|
||||
' LEFT JOIN file_to_post ON file_to_post.file_id=file.id'.
|
||||
' WHERE'.
|
||||
' NOT EXISTS (SELECT file_to_post.file_id FROM file_to_post WHERE file.id=file_to_post.file_id)'.
|
||||
' OR NOT EXISTS (SELECT notice.id FROM notice WHERE notice.id=file_to_post.post_id)'.
|
||||
' GROUP BY file.id;';
|
||||
$sql = <<<'END'
|
||||
SELECT file.*
|
||||
FROM file_to_post
|
||||
INNER JOIN notice ON file_to_post.post_id = notice.id
|
||||
RIGHT JOIN file ON file_to_post.file_id = file.id
|
||||
WHERE file_to_post.file_id IS NULL;
|
||||
END;
|
||||
|
||||
if ($file->query($sql) !== false) {
|
||||
print " {$file->N} found.\n";
|
||||
|
||||
Reference in New Issue
Block a user