Avoid ordering just by a timestamp

Try to also employ an id when possible.
Involves reworking some of the indices.
This commit is contained in:
Alexei Sorokin
2020-09-15 16:59:27 +03:00
committed by Diogo Peralta Cordeiro
parent ae4f3176b1
commit a0f72fe5c6
41 changed files with 633 additions and 656 deletions

View File

@@ -129,12 +129,12 @@ class apActorLikedAction extends ManagedAction
$limit = 40,
$since_id = null,
$max_id = null
) {
) {
$fav = new Fave();
$fav->user_id = $user_id;
$fav->orderBy('modified DESC');
$fav->orderBy('modified DESC, notice_id DESC');
if ($since_id != null) {
$fav->whereAdd("notice_id > {$since_id}");

View File

@@ -45,7 +45,7 @@ function testAllUsers($filter, $minimum, $percent)
do {
$user = new User();
$user->orderBy('created');
$user->orderBy('created, id');
$user->limit($offset, $limit);
$found = $user->find();

View File

@@ -16,8 +16,6 @@
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* Description of this file.
*
* @package GNUsocial
* @copyright 2012 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
@@ -48,7 +46,7 @@ function testAllUsers($filter)
do {
$user = new User();
$user->orderBy('created');
$user->orderBy('created, id');
$user->limit($offset, $limit);
$found = $user->find();

View File

@@ -73,9 +73,9 @@ class Bookmark extends Managed_DataObject
'bookmark_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
'bookmark_uri_fkey' => array('notice', array('uri' => 'uri')),
),
'indexes' => array('bookmark_created_idx' => array('created'),
'bookmark_url_idx' => array('url'),
'bookmark_profile_id_idx' => array('profile_id'),
'indexes' => array(
'bookmark_url_idx' => array('url'),
'bookmark_profile_id_created_idx' => array('profile_id', 'created'),
),
);
}

View File

@@ -30,31 +30,29 @@ class RawBookmarksNoticeStream extends NoticeStream
public function getNoticeIds($offset, $limit, $since_id, $max_id)
{
$notice = new Notice();
$qry = null;
$qry = 'SELECT notice.* FROM notice ';
$qry .= 'INNER JOIN bookmark ON bookmark.uri = notice.uri ';
$qry .= 'WHERE bookmark.profile_id = ' . $this->user_id . ' ';
$qry .= 'AND notice.is_local <> ' . Notice::GATEWAY . ' ';
$notice->selectAdd();
$notice->selectAdd('notice.*');
if ($since_id != 0) {
$qry .= 'AND notice.id > ' . $since_id . ' ';
}
$notice->joinAdd(['uri', 'bookmark:uri']);
if ($max_id != 0) {
$qry .= 'AND notice.id <= ' . $max_id . ' ';
}
$notice->whereAdd(sprintf('bookmark.profile_id = %d', $this->user_id));
$notice->whereAdd('notice.is_local <> ' . Notice::GATEWAY);
Notice::addWhereSinceId($notice, $since_id, 'notice.id', 'bookmark.created');
Notice::addWhereMaxId($notice, $max_id, 'notice.id', 'bookmark.created');
// NOTE: we sort by bookmark time, not by notice time!
$qry .= 'ORDER BY created DESC ';
$notice->orderBy('bookmark.created DESC');
if (!is_null($offset)) {
$qry .= "LIMIT $limit OFFSET $offset";
$notice->limit($offset, $limit);
}
$notice->query($qry);
$ids = array();
while ($notice->fetch()) {
$ids[] = $notice->id;
$ids = [];
if ($notice->find()) {
while ($notice->fetch()) {
$ids[] = $notice->id;
}
}
$notice->free();

View File

@@ -208,7 +208,7 @@ class DirectMessagePlugin extends Plugin
$message->selectAdd(); // clears it
$message->selectAdd('id');
$message->orderBy('created ASC');
$message->orderBy('created, id');
if ($message->find()) {
while ($message->fetch()) {

View File

@@ -82,11 +82,8 @@ class Message extends Managed_DataObject
'message_to_profile_fkey' => array('profile', array('to_profile' => 'id')),
),
'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_profile_idx' => array('from_profile'),
'message_to_profile_idx' => array('to_profile'),
'message_created_idx' => array('created'),
'message_from_profile_created_id_idx' => array('from_profile', 'created', 'id'),
'message_to_profile_created_id_idx' => array('to_profile', 'created', 'id'),
),
);
}

View File

@@ -21,30 +21,28 @@ class RawEventsNoticeStream extends NoticeStream
public function getNoticeIds($offset, $limit, $since_id, $max_id)
{
$notice = new Notice();
$qry = null;
$qry = 'SELECT notice.* FROM notice ';
$qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
$qry .= 'AND notice.is_local <> ' . Notice::GATEWAY . ' ';
$notice->selectAdd();
$notice->selectAdd('notice.*');
if ($since_id != 0) {
$qry .= 'AND notice.id > ' . $since_id . ' ';
}
$notice->joinAdd(['uri', 'happening:uri']);
if ($max_id != 0) {
$qry .= 'AND notice.id <= ' . $max_id . ' ';
}
$notice->whereAdd('notice.is_local <> ' . Notice::GATEWAY);
Notice::addWhereSinceId($notice, $since_id, 'notice.id', 'happening.created');
Notice::addWhereMaxId($notice, $max_id, 'notice.id', 'happening.created');
// NOTE: we sort by event time, not by notice time!
$qry .= 'ORDER BY happening.created DESC ';
$notice->orderBy('happening.created DESC');
if (!is_null($offset)) {
$qry .= "LIMIT $limit OFFSET $offset";
$notice->limit($offset, $limit);
}
$notice->query($qry);
$ids = array();
while ($notice->fetch()) {
$ids[] = $notice->id;
$ids = [];
if ($notice->find()) {
while ($notice->fetch()) {
$ids[] = $notice->id;
}
}
$notice->free();

View File

@@ -1,48 +1,41 @@
<?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 group direct messages
*
* 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) 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/>.
* @category Data
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
/**
* Data class for group direct messages
*
* @category GroupPrivateMessage
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* @see DB_DataObject
* @category GroupPrivateMessage
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class Group_message extends Managed_DataObject
{
@@ -81,20 +74,22 @@ class Group_message extends Managed_DataObject
),
'indexes' => array(
'group_message_from_profile_idx' => array('from_profile'),
'group_message_to_group_idx' => array('to_group'),
'group_message_to_group_created_idx' => array('to_group', 'created'),
'group_message_url_idx' => array('url'),
),
);
}
static function send($user, $group, $text)
public static function send($user, $group, $text)
{
if (!$user->hasRight(Right::NEWMESSAGE)) {
// XXX: maybe break this out into a separate right
// TRANS: Exception thrown when trying to send group private message without having the right to do that.
// TRANS: %s is a user nickname.
throw new Exception(sprintf(_m('User %s is not allowed to send private messages.'),
$user->nickname));
throw new Exception(sprintf(
_m('User %s is not allowed to send private messages.'),
$user->nickname
));
}
Group_privacy_settings::ensurePost($user, $group);
@@ -106,10 +101,14 @@ class Group_message extends Managed_DataObject
if (Message::contentTooLong($text)) {
// TRANS: Exception thrown when trying to send group private message that is too long.
// TRANS: %d is the maximum meggage length.
throw new Exception(sprintf(_m('That\'s too long. Maximum message size is %d character.',
'That\'s too long. Maximum message size is %d characters.',
Message::maxContent()),
Message::maxContent()));
throw new Exception(sprintf(
_m(
'That\'s too long. Maximum message size is %d character.',
'That\'s too long. Maximum message size is %d characters.',
Message::maxContent()
),
Message::maxContent()
));
}
// Valid! Let's do this thing!
@@ -134,7 +133,7 @@ class Group_message extends Managed_DataObject
return $gm;
}
function distribute()
public function distribute()
{
$group = User_group::getKV('id', $this->to_group);
@@ -145,7 +144,7 @@ class Group_message extends Managed_DataObject
}
}
function getGroup()
public function getGroup()
{
$group = User_group::getKV('id', $this->to_group);
if (empty($group)) {
@@ -155,7 +154,7 @@ class Group_message extends Managed_DataObject
return $group;
}
function getSender()
public function getSender()
{
$sender = Profile::getKV('id', $this->from_profile);
if (empty($sender)) {
@@ -165,7 +164,7 @@ class Group_message extends Managed_DataObject
return $sender;
}
static function forGroup($group, $offset, $limit)
public static function forGroup($group, $offset, $limit)
{
// XXX: cache
$gm = new Group_message();

View File

@@ -1,34 +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/>.
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* Throttle registration by IP address
*
* 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 Spam
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 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('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Throttle registration by IP address
@@ -36,11 +32,10 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* We a) record IP address of registrants and b) throttle registrations.
*
* @category Spam
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 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
*/
class RegisterThrottlePlugin extends Plugin
@@ -73,7 +68,7 @@ class RegisterThrottlePlugin extends Plugin
/**
* Whether we're enabled; prevents recursion.
*/
static private $enabled = true;
private static $enabled = true;
/**
* Database schema setup
@@ -93,9 +88,11 @@ class RegisterThrottlePlugin extends Plugin
public function onRouterInitialized(URLMapper $m)
{
$m->connect('main/ipregistrations/:ipaddress',
['action' => 'ipregistrations'],
['ipaddress' => '[0-9a-f\.\:]+']);
$m->connect(
'main/ipregistrations/:ipaddress',
['action' => 'ipregistrations'],
['ipaddress' => '[0-9a-f\.\:]+']
);
}
/**
@@ -118,7 +115,6 @@ class RegisterThrottlePlugin extends Plugin
}
foreach ($this->regLimits as $seconds => $limit) {
$this->debug("Checking $seconds ($limit)");
$reg = $this->_getNthReg($ipaddress, $limit);
@@ -151,7 +147,7 @@ class RegisterThrottlePlugin extends Plugin
return true;
}
function onEndShowSections(Action $action)
public function onEndShowSections(Action $action)
{
if (!$action instanceof ShowstreamAction) {
// early return for actions we're not interested in
@@ -188,11 +184,17 @@ class RegisterThrottlePlugin extends Plugin
$attrs = ['class'=>'ipaddress'];
if (!is_null($ipaddress)) {
$el = 'a';
$attrs['href'] = common_local_url('ipregistrations', array('ipaddress'=>$ipaddress));
$attrs['href'] = common_local_url(
'ipregistrations',
['ipaddress' => $ipaddress]
);
}
$action->element($el, $attrs,
// TRANS: Unknown IP address.
$ipaddress ?: _('unknown'));
$action->element(
$el,
$attrs,
// TRANS: Unknown IP address.
$ipaddress ?? _('unknown')
);
$action->elementEnd('div');
}
@@ -285,7 +287,7 @@ class RegisterThrottlePlugin extends Plugin
$reg->ipaddress = $ipaddress;
$reg->orderBy('created DESC');
$reg->orderBy('created DESC, user_id DESC');
$reg->limit($n - 1, 1);
if ($reg->find(true)) {

View File

@@ -1,42 +1,39 @@
<?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 storing IP addresses of new registrants.
*
* 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) 2010, 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 2010 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 storing IP addresses of new registrants.
*
* @category Spam
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Spam
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class Registration_ip extends Managed_DataObject
{
@@ -60,8 +57,7 @@ class Registration_ip extends Managed_DataObject
'registration_ip_user_id_fkey' => array('user', array('user_id' => 'id')),
),
'indexes' => array(
'registration_ip_ipaddress_idx' => array('ipaddress'),
'registration_ip_created_idx' => array('created'),
'registration_ip_ipaddress_created_idx' => array('ipaddress', 'created'),
),
);
}
@@ -73,7 +69,7 @@ class Registration_ip extends Managed_DataObject
*
* @return Array IDs of users who registered with this address.
*/
static function usersByIP($ipaddress)
public static function usersByIP($ipaddress)
{
$ids = array();

View File

@@ -1,51 +1,46 @@
<?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
*
* Show list of user pages
*
* 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 <http://www.gnu.org/licenses/>.
*
* @category Sitemap
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 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')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* sitemap for users
*
* @category Sitemap
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @category Sitemap
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class NoticesitemapAction extends SitemapAction
{
var $notices = null;
var $j = 0;
public $notices = null;
public $j = 0;
function prepare(array $args = array())
public function prepare(array $args = [])
{
parent::prepare($args);
@@ -67,7 +62,7 @@ class NoticesitemapAction extends SitemapAction
return true;
}
function nextUrl()
public function nextUrl()
{
if ($this->j < count($this->notices)) {
$n = $this->notices[$this->j];
@@ -81,12 +76,11 @@ class NoticesitemapAction extends SitemapAction
}
}
function getNotices($y, $m, $d, $i)
public function getNotices($y, $m, $d, $i)
{
$n = Notice::cacheGet("sitemap:notice:$y:$m:$d:$i");
$n = Notice::cacheGet("sitemap:notice:{$y}:{$m}:{$d}:{$i}");
if ($n === false) {
$notice = new Notice();
$begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
@@ -106,7 +100,7 @@ class NoticesitemapAction extends SitemapAction
$notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
$notice->orderBy('created');
$notice->orderBy('created, id');
$offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP;
$limit = SitemapPlugin::NOTICES_PER_MAP;
@@ -124,10 +118,12 @@ class NoticesitemapAction extends SitemapAction
$c = Cache::instance();
if (!empty($c)) {
$c->set(Cache::key("sitemap:notice:$y:$m:$d:$i"),
$n,
Cache::COMPRESSED,
((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
$c->set(
Cache::key("sitemap:notice:$y:$m:$d:$i"),
$n,
Cache::COMPRESSED,
((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60))
);
}
}

View File

@@ -1,51 +1,46 @@
<?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
*
* Show list of user pages
*
* 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 <http://www.gnu.org/licenses/>.
*
* @category Sitemap
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 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')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* sitemap for users
*
* @category Sitemap
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @category Sitemap
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class UsersitemapAction extends SitemapAction
{
var $users = null;
var $j = 0;
public $users = null;
public $j = 0;
function prepare(array $args = array())
public function prepare(array $args = [])
{
parent::prepare($args);
@@ -66,7 +61,7 @@ class UsersitemapAction extends SitemapAction
return true;
}
function nextUrl()
public function nextUrl()
{
if ($this->j < count($this->users)) {
$nickname = $this->users[$this->j];
@@ -77,12 +72,11 @@ class UsersitemapAction extends SitemapAction
}
}
function getUsers($y, $m, $d, $i)
public function getUsers($y, $m, $d, $i)
{
$u = User::cacheGet("sitemap:user:$y:$m:$d:$i");
if ($u === false) {
$user = new User();
$begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
@@ -99,7 +93,7 @@ class UsersitemapAction extends SitemapAction
$user->whereAdd("created >= '$begindt'");
$user->whereAdd("created < '$enddt'");
$user->orderBy('created');
$user->orderBy('created, id');
$offset = ($i-1) * SitemapPlugin::USERS_PER_MAP;
$limit = SitemapPlugin::USERS_PER_MAP;
@@ -115,10 +109,12 @@ class UsersitemapAction extends SitemapAction
$c = Cache::instance();
if (!empty($c)) {
$c->set(Cache::key("sitemap:user:$y:$m:$d:$i"),
$u,
Cache::COMPRESSED,
((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
$c->set(
Cache::key("sitemap:user:{$y}:{$m}:{$d}:{$i}"),
$u,
Cache::COMPRESSED,
((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60))
);
}
}

View File

@@ -1,58 +1,46 @@
<?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) 2010, StatusNet, Inc.
*
* Plugin to throttle subscriptions by a user
*
* 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 Throttle
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 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')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Subscription throttle
*
* @category Throttle
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 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
*/
class SubscriptionThrottlePlugin extends Plugin
{
const PLUGIN_VERSION = '2.0.0';
public $subLimits = array(86400 => 100,
3600 => 50);
public $groupLimits = array(86400 => 50,
3600 => 25);
public $subLimits = [86400 => 100, 3600 => 50];
public $groupLimits = [86400 => 50, 3600 => 25];
/**
* Filter subscriptions to see if they're coming too fast.
@@ -62,7 +50,7 @@ class SubscriptionThrottlePlugin extends Plugin
*
* @return boolean hook value
*/
function onStartSubscribe(Profile $profile, $other)
public function onStartSubscribe(Profile $profile, $other)
{
foreach ($this->subLimits as $seconds => $limit) {
$sub = $this->_getNthSub($profile, $limit);
@@ -88,12 +76,11 @@ class SubscriptionThrottlePlugin extends Plugin
*
* @return boolean hook value
*/
function onStartJoinGroup($group, $profile)
public function onStartJoinGroup($group, $profile)
{
foreach ($this->groupLimits as $seconds => $limit) {
$mem = $this->_getNthMem($profile, $limit);
if (!empty($mem)) {
$jointime = strtotime($mem->created);
$now = time();
if ($now - $jointime < $seconds) {
@@ -142,7 +129,7 @@ class SubscriptionThrottlePlugin extends Plugin
$mem = new Group_member();
$mem->profile_id = $profile->id;
$mem->orderBy('created DESC');
$mem->orderBy('created DESC, group_id DESC');
$mem->limit($n - 1, 1);
if ($mem->find(true)) {

View File

@@ -1,47 +1,39 @@
<?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/>.
/**
* Show latest and greatest profile flags
*
* PHP version 5
*
* @category Action
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
*
* @see http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 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/>.
* @category Action
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Show the latest and greatest profile flags
*
* @category Action
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
*
* @see http://status.net/
* @category Action
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class AdminprofileflagAction extends Action
{
@@ -139,8 +131,12 @@ class AdminprofileflagAction extends Action
$cnt = $pl->show();
$this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
$this->page, 'adminprofileflag');
$this->pagination(
$this->page > 1,
$cnt > PROFILES_PER_PAGE,
$this->page,
'adminprofileflag'
);
}
/**
@@ -188,13 +184,11 @@ class AdminprofileflagAction extends Action
*
* Most of the hard part is done in FlaggedProfileListItem.
*
* @category Widget
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
*
* @see http://status.net/
* @category Widget
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class FlaggedProfileList extends ProfileList
{
@@ -214,13 +208,11 @@ class FlaggedProfileList extends ProfileList
/**
* Specialization of ProfileListItem to show flagging information
*
* @category Widget
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
*
* @see http://status.net/
* @category Widget
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class FlaggedProfileListItem extends ProfileListItem
{
@@ -354,7 +346,7 @@ class FlaggedProfileListItem extends ProfileListItem
$ufp->selectAdd();
$ufp->selectAdd('user_id');
$ufp->profile_id = $this->profile->id;
$ufp->orderBy('created');
$ufp->orderBy('created, user_id');
if ($ufp->find()) { // XXX: this should always happen
while ($ufp->fetch()) {
@@ -376,12 +368,16 @@ class FlaggedProfileListItem extends ProfileListItem
$lnks = [];
foreach ($flaggers as $flagger) {
$url = common_local_url('showstream',
['nickname' => $flagger->nickname]);
$url = common_local_url(
'showstream',
['nickname' => $flagger->nickname]
);
$lnks[] = XMLStringer::estring('a', ['href' => $url,
'class' => 'flagger', ],
$flagger->nickname);
$lnks[] = XMLStringer::estring(
'a',
['href' => $url, 'class' => 'flagger'],
$flagger->nickname
);
}
if ($cnt > 0) {

View File

@@ -19,11 +19,11 @@
*
* @category Data
* @package GNUsocial
*
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
@@ -33,7 +33,6 @@ defined('GNUSOCIAL') || die();
*
* @category Action
* @package GNUsocial
*
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
@@ -65,8 +64,8 @@ class User_flag_profile extends Managed_DataObject
],
'primary key' => ['profile_id', 'user_id'],
'indexes' => [
'user_flag_profile_cleared_idx' => ['cleared'],
'user_flag_profile_created_idx' => ['created'],
'user_flag_profile_cleared_profile_id_idx' => ['cleared', 'profile_id'],
'user_flag_profile_profile_id_created_user_id_idx' => ['profile_id', 'created', 'user_id'],
],
];
}