Some SQL and indexes improvements
This commit is contained in:
parent
c567131ca7
commit
b51fc38783
|
@ -573,7 +573,12 @@ function listBoards() {
|
||||||
function checkFlood($post) {
|
function checkFlood($post) {
|
||||||
global $board, $config;
|
global $board, $config;
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`ip` = :ip AND `time` >= :floodtime) OR (`ip` = :ip AND `body` != '' AND `body` = :body AND `time` >= :floodsameiptime) OR (`body` != '' AND `body` = :body AND `time` >= :floodsametime) LIMIT 1", $board['uri']));
|
$query = prepare(sprintf("SELECT COUNT(*) FROM ``posts_%s`` WHERE
|
||||||
|
(`ip` = :ip AND `time` >= :floodtime)
|
||||||
|
OR
|
||||||
|
(`ip` = :ip AND :body != '' AND `body_nomarkup` = :body AND `time` >= :floodsameiptime)
|
||||||
|
OR
|
||||||
|
(:body != '' AND `body_nomarkup` = :body AND `time` >= :floodsametime) LIMIT 1", $board['uri']));
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->bindValue(':body', $post['body']);
|
$query->bindValue(':body', $post['body']);
|
||||||
$query->bindValue(':floodtime', time()-$config['flood_time'], PDO::PARAM_INT);
|
$query->bindValue(':floodtime', time()-$config['flood_time'], PDO::PARAM_INT);
|
||||||
|
@ -581,7 +586,7 @@ function checkFlood($post) {
|
||||||
$query->bindValue(':floodsametime', time()-$config['flood_time_same'], PDO::PARAM_INT);
|
$query->bindValue(':floodsametime', time()-$config['flood_time_same'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$flood = (bool) $query->fetch(PDO::FETCH_ASSOC);
|
$flood = (bool) $query->fetchColumn();
|
||||||
|
|
||||||
if (event('check-flood', $post))
|
if (event('check-flood', $post))
|
||||||
return true;
|
return true;
|
||||||
|
@ -658,12 +663,12 @@ function checkBan($board = 0) {
|
||||||
if (event('check-ban', $board))
|
if (event('check-ban', $board))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, ``bans``.`id` FROM ``bans`` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
|
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, `id` FROM ``bans`` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->bindValue(':board', $board);
|
$query->bindValue(':board', $board);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
if ($query->rowCount() < 1 && $config['ban_range']) {
|
if ($query->rowCount() < 1 && $config['ban_range']) {
|
||||||
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, ``bans``.`id` FROM ``bans`` WHERE (`board` IS NULL OR `board` = :board) AND :ip LIKE REPLACE(REPLACE(`ip`, '%', '!%'), '*', '%') ESCAPE '!' ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
|
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, `id` FROM ``bans`` WHERE (`board` IS NULL OR `board` = :board) AND :ip LIKE REPLACE(REPLACE(`ip`, '%', '!%'), '*', '%') ESCAPE '!' ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->bindValue(':board', $board);
|
$query->bindValue(':board', $board);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
@ -1229,14 +1234,11 @@ function checkRobot($body) {
|
||||||
// Returns an associative array with 'replies' and 'images' keys
|
// Returns an associative array with 'replies' and 'images' keys
|
||||||
function numPosts($id) {
|
function numPosts($id) {
|
||||||
global $board;
|
global $board;
|
||||||
$query = prepare(sprintf("SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(*) FROM ``posts_%s`` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
|
$query = prepare(sprintf("SELECT COUNT(*) AS `replies`, COUNT(NULLIF(`file`, 0)) AS `images` FROM ``posts_%s`` WHERE `thread` = :thread", $board['uri'], $board['uri']));
|
||||||
$query->bindValue(':thread', $id, PDO::PARAM_INT);
|
$query->bindValue(':thread', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$num_posts = $query->fetchColumn();
|
return $query->fetch(PDO::FETCH_ASSOC);
|
||||||
$num_images = $query->fetchColumn();
|
|
||||||
|
|
||||||
return array('replies' => $num_posts, 'images' => $num_images);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function muteTime() {
|
function muteTime() {
|
||||||
|
|
13
install.php
13
install.php
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Installation/upgrade file
|
// Installation/upgrade file
|
||||||
define('VERSION', 'v0.9.6-dev-14');
|
define('VERSION', 'v0.9.6-dev-15');
|
||||||
|
|
||||||
require 'inc/functions.php';
|
require 'inc/functions.php';
|
||||||
|
|
||||||
|
@ -370,6 +370,17 @@ if (file_exists($config['has_installed'])) {
|
||||||
}
|
}
|
||||||
case 'v0.9.6-dev-13':
|
case 'v0.9.6-dev-13':
|
||||||
query("ALTER TABLE ``antispam`` ADD INDEX `expires` (`expires`)") or error(db_error());
|
query("ALTER TABLE ``antispam`` ADD INDEX `expires` (`expires`)") or error(db_error());
|
||||||
|
case 'v0.9.6-dev-14':
|
||||||
|
foreach ($boards as &$board) {
|
||||||
|
query(sprintf("ALTER TABLE ``posts_%s``
|
||||||
|
DROP INDEX `body`,
|
||||||
|
ADD INDEX `filehash` (`filehash`(40))", $board['uri'])) or error(db_error());
|
||||||
|
}
|
||||||
|
query("ALTER TABLE ``modlogs`` ADD INDEX `mod` (`mod`)") or error(db_error());
|
||||||
|
query("ALTER TABLE ``bans`` DROP INDEX `ip`") or error(db_error());
|
||||||
|
query("ALTER TABLE ``bans`` ADD INDEX `ip` (`ip`)") or error(db_error());
|
||||||
|
query("ALTER TABLE ``noticeboard`` ADD INDEX `time` (`time`)") or error(db_error());
|
||||||
|
query("ALTER TABLE ``pms`` ADD INDEX `to` (`to`, `unread`)") or error(db_error());
|
||||||
case false:
|
case false:
|
||||||
// Update version number
|
// Update version number
|
||||||
file_write($config['has_installed'], VERSION);
|
file_write($config['has_installed'], VERSION);
|
||||||
|
|
11
install.sql
11
install.sql
|
@ -49,7 +49,7 @@ CREATE TABLE IF NOT EXISTS `bans` (
|
||||||
`board` varchar(58) CHARACTER SET utf8 DEFAULT NULL,
|
`board` varchar(58) CHARACTER SET utf8 DEFAULT NULL,
|
||||||
`seen` tinyint(1) NOT NULL,
|
`seen` tinyint(1) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
FULLTEXT KEY `ip` (`ip`)
|
KEY `ip` (`ip`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
@ -115,7 +115,8 @@ CREATE TABLE IF NOT EXISTS `modlogs` (
|
||||||
`board` varchar(58) CHARACTER SET utf8 DEFAULT NULL,
|
`board` varchar(58) CHARACTER SET utf8 DEFAULT NULL,
|
||||||
`time` int(11) NOT NULL,
|
`time` int(11) NOT NULL,
|
||||||
`text` text NOT NULL,
|
`text` text NOT NULL,
|
||||||
KEY `time` (`time`)
|
KEY `time` (`time`),
|
||||||
|
KEY `mod`(`mod`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
@ -182,7 +183,8 @@ CREATE TABLE IF NOT EXISTS `noticeboard` (
|
||||||
`time` int(11) NOT NULL,
|
`time` int(11) NOT NULL,
|
||||||
`subject` text NOT NULL,
|
`subject` text NOT NULL,
|
||||||
`body` text NOT NULL,
|
`body` text NOT NULL,
|
||||||
UNIQUE KEY `id` (`id`)
|
UNIQUE KEY `id` (`id`),
|
||||||
|
KEY `time` (`time`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
@ -198,7 +200,8 @@ CREATE TABLE IF NOT EXISTS `pms` (
|
||||||
`message` text NOT NULL,
|
`message` text NOT NULL,
|
||||||
`time` int(11) NOT NULL,
|
`time` int(11) NOT NULL,
|
||||||
`unread` tinyint(1) NOT NULL,
|
`unread` tinyint(1) NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `to` (`to`, `unread`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
11
post.php
11
post.php
|
@ -427,6 +427,12 @@ if (isset($_POST['delete'])) {
|
||||||
error(sprintf($config['error']['toolong'], 'password'));
|
error(sprintf($config['error']['toolong'], 'password'));
|
||||||
|
|
||||||
wordfilters($post['body']);
|
wordfilters($post['body']);
|
||||||
|
|
||||||
|
// Check for a flood
|
||||||
|
if (!hasPermission($config['mod']['flood'], $board['uri']) && checkFlood($post)) {
|
||||||
|
error($config['error']['flood']);
|
||||||
|
}
|
||||||
|
|
||||||
$post['body'] = escape_markup_modifiers($post['body']);
|
$post['body'] = escape_markup_modifiers($post['body']);
|
||||||
|
|
||||||
if ($mod && isset($post['raw']) && $post['raw']) {
|
if ($mod && isset($post['raw']) && $post['raw']) {
|
||||||
|
@ -463,11 +469,6 @@ if (isset($_POST['delete'])) {
|
||||||
|
|
||||||
$post['tracked_cites'] = markup($post['body'], true);
|
$post['tracked_cites'] = markup($post['body'], true);
|
||||||
|
|
||||||
// Check for a flood
|
|
||||||
if (!hasPermission($config['mod']['flood'], $board['uri']) && checkFlood($post)) {
|
|
||||||
error($config['error']['flood']);
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once 'inc/filters.php';
|
require_once 'inc/filters.php';
|
||||||
|
|
||||||
do_filters($post);
|
do_filters($post);
|
||||||
|
|
|
@ -27,8 +27,8 @@ CREATE TABLE IF NOT EXISTS ``posts_{{ board }}`` (
|
||||||
`embed` text,
|
`embed` text,
|
||||||
UNIQUE KEY `id` (`id`),
|
UNIQUE KEY `id` (`id`),
|
||||||
KEY `thread_id` (`thread`,`id`),
|
KEY `thread_id` (`thread`,`id`),
|
||||||
|
KEY `filehash` (`filehash`),
|
||||||
KEY `time` (`time`),
|
KEY `time` (`time`),
|
||||||
FULLTEXT KEY `body` (`body`),
|
|
||||||
KEY `ip` (`ip`)
|
KEY `ip` (`ip`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
|
||||||
|
|
Loading…
Reference in New Issue