[DATABASE] Fix index identifiers and clean up redundant ones

This commit is contained in:
Alexei Sorokin
2020-07-31 16:12:48 +03:00
committed by Diogo Peralta Cordeiro
parent f3ab63957d
commit 665e4574da
33 changed files with 249 additions and 259 deletions

View File

@@ -28,7 +28,7 @@ defined('GNUSOCIAL') || die();
/**
* Table definition for message.
*
*
* Since the new updates this class only has the necessary
* logic to upgrade te plugin.
*
@@ -84,24 +84,24 @@ class Message extends Managed_DataObject
'indexes' => array(
// @fixme these are really terrible indexes, since you can only sort on one of them at a time.
// looks like we really need a (to_profile, created) for inbox and a (from_profile, created) for outbox
'message_from_idx' => array('from_profile'),
'message_to_idx' => array('to_profile'),
'message_from_profile_idx' => array('from_profile'),
'message_to_profile_idx' => array('to_profile'),
'message_created_idx' => array('created'),
),
);
}
function getFrom()
public function getFrom()
{
return Profile::getKV('id', $this->from_profile);
}
function getTo()
public function getTo()
{
return Profile::getKV('id', $this->to_profile);
}
function getSource()
public function getSource()
{
if (empty($this->source)) {
return false;
@@ -133,7 +133,7 @@ class Message extends Managed_DataObject
return $ns;
}
function asActivity()
public function asActivity()
{
$act = new Activity();

View File

@@ -135,7 +135,7 @@ class Email_reminder extends Managed_DataObject
),
'primary key' => array('type', 'code', 'days'),
'indexes' => array(
'sent_idx' => array('sent'),
'email_reminder_sent_idx' => array('sent'),
),
);
}

View File

@@ -1,33 +1,30 @@
<?php
// 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/>.
/**
* Data class for happenings
*
* PHP version 5
*
* @category Data
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, 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/>.
* @category Data
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Data class for happenings
@@ -37,13 +34,12 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*
* "Happening" seemed good enough.
*
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Event
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see Managed_DataObject
* @see Managed_DataObject
*/
class Happening extends Managed_DataObject
{
@@ -98,8 +94,10 @@ class Happening extends Managed_DataObject
'happening_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
'happening_uri_fkey' => array('notice', array('uri' => 'uri'))
),
'indexes' => array('happening_created_idx' => array('created'),
'happening_start_end_idx' => array('start_time', 'end_time')),
'indexes' => array(
'happening_created_idx' => array('created'),
'happening_start_time_end_time_idx' => array('start_time', 'end_time'),
),
);
}
@@ -129,25 +127,26 @@ class Happening extends Managed_DataObject
foreach ($actobj->extra as $extra) {
switch ($extra[0]) {
case 'dtstart':
$dtstart = $extra[2];
case 'dtend':
$dtend = $extra[2];
break;
case 'location':
// location is optional
$location = $extra[2];
break;
case 'url':
// url is optional
$url = $extra[2];
case 'dtstart':
$dtstart = $extra[2];
break;
case 'dtend':
$dtend = $extra[2];
break;
case 'location':
// location is optional
$location = $extra[2];
break;
case 'url':
// url is optional
$url = $extra[2];
}
}
if(empty($dtstart)) {
if (empty($dtstart)) {
// TRANS: Exception thrown when has no start date
throw new Exception(_m('No start date for event.'));
}
if(empty($dtend)) {
if (empty($dtend)) {
// TRANS: Exception thrown when has no end date
throw new Exception(_m('No end date for event.'));
}
@@ -211,7 +210,7 @@ class Happening extends Managed_DataObject
return Notice::getByKeys(array('uri'=>$this->getUri()));
}
static function fromStored(Notice $stored)
public static function fromStored(Notice $stored)
{
if (!ActivityUtils::compareTypes($stored->getObjectType(), [self::OBJECT_TYPE])) {
throw new ServerException('Notice is not of type '.self::OBJECT_TYPE);
@@ -219,18 +218,20 @@ class Happening extends Managed_DataObject
return self::getByKeys(array('uri'=>$stored->getUri()));
}
function getRSVPs()
public function getRSVPs()
{
return RSVP::forEvent($this);
}
function getRSVP($profile)
public function getRSVP($profile)
{
return RSVP::pkeyGet(array('profile_id' => $profile->getID(),
'event_uri' => $this->getUri()));
return RSVP::pkeyGet([
'profile_id' => $profile->getID(),
'event_uri' => $this->getUri(),
]);
}
static public function getObjectType()
public static function getObjectType()
{
return self::OBJECT_TYPE;
}

View File

@@ -1,44 +1,40 @@
<?php
// 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/>.
/**
* Data class for event RSVPs
*
* PHP version 5
*
* @category Data
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, 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/>.
* @category Data
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Data class for event RSVPs
*
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Event
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see Managed_DataObject
* @see Managed_DataObject
*/
class RSVP extends Managed_DataObject
{
@@ -83,7 +79,7 @@ class RSVP extends Managed_DataObject
'primary key' => array('id'),
'unique keys' => array(
'rsvp_uri_key' => array('uri'),
'rsvp_profile_event_key' => array('profile_id', 'event_uri'),
'rsvp_profile_id_event_uri_key' => array('profile_id', 'event_uri'),
),
'foreign keys' => array(
'rsvp_event_uri_fkey' => array('happening', array('event_uri' => 'uri')),
@@ -93,7 +89,7 @@ class RSVP extends Managed_DataObject
);
}
static public function beforeSchemaUpdate()
public static function beforeSchemaUpdate()
{
$table = strtolower(get_called_class());
$schema = Schema::get();
@@ -128,7 +124,7 @@ class RSVP extends Managed_DataObject
print "Resuming core schema upgrade...";
}
static function saveActivityObject(Activity $act, Notice $stored)
public static function saveActivityObject(Activity $act, Notice $stored)
{
$target = Notice::getByKeys(array('uri'=>$act->target->id));
if (!ActivityUtils::compareTypes($target->getObjectType(), [ Happening::OBJECT_TYPE ])) {
@@ -138,9 +134,10 @@ class RSVP extends Managed_DataObject
// FIXME: Maybe we need some permission handling here, though I think it's taken care of in saveActivity?
try {
$other = RSVP::getByKeys( [ 'profile_id' => $stored->getProfile()->getID(),
'event_uri' => $target->getUri(),
] );
$other = RSVP::getByKeys([
'profile_id' => $stored->getProfile()->getID(),
'event_uri' => $target->getUri(),
]);
// TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond").
throw new AlreadyFulfilledException(_m('RSVP already exists.'));
} catch (NoResultException $e) {
@@ -162,7 +159,7 @@ class RSVP extends Managed_DataObject
return $rsvp;
}
static public function getObjectType()
public static function getObjectType()
{
return ActivityObject::ACTIVITY;
}
@@ -181,7 +178,7 @@ class RSVP extends Managed_DataObject
return $actobj;
}
static function codeFor($verb)
public static function codeFor($verb)
{
switch (true) {
case ActivityUtils::compareVerbs($verb, [RSVP::POSITIVE]):
@@ -195,11 +192,11 @@ class RSVP extends Managed_DataObject
break;
default:
// TRANS: Exception thrown when requesting an undefined verb for RSVP.
throw new Exception(sprintf(_m('Unknown verb "%s".'),$verb));
throw new Exception(sprintf(_m('Unknown verb "%s".'), $verb));
}
}
static function verbFor($code)
public static function verbFor($code)
{
switch ($code) {
case 'Y':
@@ -235,18 +232,18 @@ class RSVP extends Managed_DataObject
return Notice::getByKeys(['uri' => $this->getUri()]);
}
static function fromStored(Notice $stored)
public static function fromStored(Notice $stored)
{
return self::getByKeys(['uri' => $stored->getUri()]);
}
static function byEventAndActor(Happening $event, Profile $actor)
public static function byEventAndActor(Happening $event, Profile $actor)
{
return self::getByKeys(['event_uri' => $event->getUri(),
'profile_id' => $actor->getID()]);
}
static function forEvent(Happening $event)
public static function forEvent(Happening $event)
{
$keypart = sprintf('rsvp:for-event:%s', $event->getUri());
@@ -287,31 +284,35 @@ class RSVP extends Managed_DataObject
return $rsvps;
}
function getProfile()
public function getProfile()
{
return Profile::getByID($this->profile_id);
}
function getEvent()
public function getEvent()
{
return Happening::getByKeys(['uri' => $this->getEventUri()]);
}
function asHTML()
public function asHTML()
{
return self::toHTML($this->getProfile(),
$this->getEvent(),
$this->response);
return self::toHTML(
$this->getProfile(),
$this->getEvent(),
$this->response
);
}
function asString()
public function asString()
{
return self::toString($this->getProfile(),
$this->getEvent(),
$this->response);
return self::toString(
$this->getProfile(),
$this->getEvent(),
$this->response
);
}
static function toHTML(Profile $profile, Happening $event, $response)
public static function toHTML(Profile $profile, Happening $event, $response)
{
$fmt = null;
@@ -337,7 +338,7 @@ class RSVP extends Managed_DataObject
default:
// TRANS: Exception thrown when requesting a user's RSVP status for a non-existing response code.
// TRANS: %s is the non-existing response code.
throw new Exception(sprintf(_m('Unknown response code %s.'),$response));
throw new Exception(sprintf(_m('Unknown response code %s.'), $response));
}
if (empty($event)) {
@@ -350,14 +351,16 @@ class RSVP extends Managed_DataObject
$eventTitle = $event->title;
}
return sprintf($fmt,
htmlspecialchars($profile->getUrl()),
htmlspecialchars($profile->getBestName()),
htmlspecialchars($eventUrl),
htmlspecialchars($eventTitle));
return sprintf(
$fmt,
htmlspecialchars($profile->getUrl()),
htmlspecialchars($profile->getBestName()),
htmlspecialchars($eventUrl),
htmlspecialchars($eventTitle)
);
}
static function toString($profile, $event, $response)
public static function toString($profile, $event, $response)
{
$fmt = null;
@@ -380,7 +383,7 @@ class RSVP extends Managed_DataObject
default:
// TRANS: Exception thrown when requesting a user's RSVP status for a non-existing response code.
// TRANS: %s is the non-existing response code.
throw new Exception(sprintf(_m('Unknown response code %s.'),$response));
throw new Exception(sprintf(_m('Unknown response code %s.'), $response));
break;
}
@@ -392,9 +395,11 @@ class RSVP extends Managed_DataObject
$eventTitle = $event->title;
}
return sprintf($fmt,
$profile->getBestName(),
$eventTitle);
return sprintf(
$fmt,
$profile->getBestName(),
$eventTitle
);
}
public function delete($useWhere=false)

View File

@@ -1,25 +1,25 @@
<?php
// 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/>.
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, 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/>.
* @copyright 1012 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* DataObject class to store extended profile fields. Allows for storing
@@ -98,7 +98,7 @@ class Profile_detail extends Managed_DataObject
],
'primary key' => ['id'],
'unique keys' => [
'profile_detail_profile_id_field_name_value_index' => ['profile_id', 'field_name', 'value_index']
'profile_detail_profile_id_field_name_value_index_key' => ['profile_id', 'field_name', 'value_index']
],
];
}

View File

@@ -48,36 +48,49 @@ class ModLog extends Managed_DataObject
*/
public static function schemaDef()
{
return array('description' => 'Log of moderation events',
'fields' => array(
'id' => array('type' => 'varchar',
'length' => 36,
'not null' => true,
'description' => 'unique event ID'),
'profile_id' => array('type' => 'int',
'not null' => true,
'description' => 'profile getting the role'),
'moderator_id' => array('type' => 'int',
'description' => 'profile granting or revoking the role'),
'role' => array('type' => 'varchar',
'length' => 32,
'not null' => true,
'description' => 'role granted or revoked'),
'is_grant' => array('type' => 'bool',
'default' => true,
'description' => 'Was this a grant or revocation of a role'),
'created' => array('type' => 'datetime',
'not null' => true,
'description' => 'date this record was created')
),
'primary key' => array('id'),
'foreign keys' => array(
'mod_log_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
'mod_log_moderator_id_fkey' => array('user', array('moderator_id' => 'id'))
),
'indexes' => array(
'mod_log_profile_id_created_idx' => array('profile_id', 'created'),
),
);
return [
'description' => 'Log of moderation events',
'fields' => [
'id' => [
'type' => 'varchar',
'length' => 36,
'not null' => true,
'description' => 'unique event ID',
],
'profile_id' => [
'type' => 'int',
'not null' => true,
'description' => 'profile getting the role',
],
'moderator_id' => [
'type' => 'int',
'description' => 'profile granting or revoking the role',
],
'role' => [
'type' => 'varchar',
'length' => 32,
'not null' => true,
'description' => 'role granted or revoked',
],
'is_grant' => [
'type' => 'bool',
'default' => true,
'description' => 'Was this a grant or revocation of a role',
],
'created' => [
'type' => 'datetime',
'not null' => true,
'description' => 'date this record was created',
],
],
'primary key' => ['id'],
'foreign keys' => [
'modlog_profile_id_fkey' => ['profile', ['profile_id' => 'id']],
'modlog_moderator_id_fkey' => ['user', ['moderator_id' => 'id']],
],
'indexes' => [
'modlog_profile_id_created_idx' => ['profile_id', 'created'],
],
];
}
}

View File

@@ -53,9 +53,6 @@ class Usage_stats extends Managed_DataObject
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
],
'primary key' => ['type'],
'indexes' => [
'user_stats_idx' => ['type'],
],
];
}

View File

@@ -1,47 +1,40 @@
<?php
// 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/>.
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2012, StatusNet, Inc.
*
* User_openid_prefs.php
*
* PHP version 5
*
* 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/>.
*
* @category OpenID
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Store preferences for OpenID use in StatusNet
*
* @category OpenID
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category OpenID
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
* @see DB_DataObject
*/
class User_openid_prefs extends Managed_DataObject
@@ -84,10 +77,10 @@ class User_openid_prefs extends Managed_DataObject
'description' => 'date this record was modified',
],
],
'primary key' => ['user_id'],
'foreign keys' => ['user_openid_prefs_user_id_fkey' => ['user', ['user_id' => 'id']],
'primary key' => ['user_id'],
'foreign keys' => [
'user_openid_prefs_user_id_fkey' => ['user', ['user_id' => 'id']],
],
'indexes' => [],
];
}
}

View File

@@ -20,7 +20,7 @@
* @category PollPlugin
* @package GNUsocial
* @author Brion Vibber <brion@status.net>
* @copyright 2011, StatusNet, Inc.
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
@@ -29,7 +29,7 @@ defined('GNUSOCIAL') || die();
/**
* For storing the poll options and such
*
* @copyright 2011, StatusNet, Inc.
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
@@ -65,7 +65,7 @@ class Poll_response extends Managed_DataObject
'poll_response_poll_id_profile_id_key' => array('poll_id', 'profile_id'),
),
'indexes' => array(
'poll_response_profile_id_poll_id_index' => array('profile_id', 'poll_id'),
'poll_response_profile_id_poll_id_idx' => array('profile_id', 'poll_id'),
)
);
}

View File

@@ -60,7 +60,7 @@ class SearchSub extends Managed_DataObject
),
'indexes' => array(
'searchsub_created_idx' => array('created'),
'searchsub_profile_id_tag_idx' => array('profile_id', 'search'),
'searchsub_profile_id_search_idx' => array('profile_id', 'search'),
),
);
}

View File

@@ -64,7 +64,7 @@ class Notice_to_status extends Managed_DataObject
),
'primary key' => array('notice_id'),
'unique keys' => array(
'status_id_key' => array('status_id'),
'notice_to_status_status_id_key' => array('status_id'),
),
'foreign keys' => array(
'notice_to_status_notice_id_fkey' => array('notice', array('notice_id' => 'id')),