Browse Source

Improve telegrams + refactor rebuilding after posts, finish reply requests before rebuilding index

This provides massive improvements to perceived post times on large boards as it doesn't wait for the entire board to rebuild index before confirming to the user that the post was made

Telegrams now send a response ajax.js can understand, redirecting them.
main
discomrade 2 years ago
parent
commit
354f70fa97
  1. 14
      js/ajax.js
  2. 72
      post.php

14
js/ajax.js

@ -58,7 +58,19 @@ $(window).ready(function() {
success: function(post_response) {
if (post_response.error) {
if (post_response.banned) {
// You are banned. Must post the form normally so the user can see the ban message.
// You are banned or warned. Must post the form normally so the user can see the ban message.
do_not_ajax = true;
$(form).find('input[type="submit"]').each(function() {
var $replacement = $('<input type="hidden">');
$replacement.attr('name', $(this).attr('name'));
$replacement.val(submit_txt);
$(this)
.after($replacement)
.replaceWith($('<input type="button">').val(submit_txt));
});
$(form).submit();
} else if (post_response.telegram) {
// You received a telegram. Must post the form normally so the user can see the telegram message.
do_not_ajax = true;
$(form).find('input[type="submit"]').each(function() {
var $replacement = $('<input type="hidden">');

72
post.php

@ -1317,36 +1317,15 @@ if (isset($_POST['delete'])) {
$query->execute() or error(db_error($query));
$telegrams = $query->fetchAll(PDO::FETCH_ASSOC);
if (count($telegrams) > 0)
goto skip_redirect;
if (!isset($_POST['json_response'])) {
header('Location: ' . $redirect, true, $config['redirect_http']);
} else {
header('Content-Type: text/json; charset=utf-8');
echo json_encode(array(
'redirect' => $redirect,
'noko' => $noko,
'id' => $id
));
}
skip_redirect:
if ($config['try_smarter'] && $post['op'])
$build_pages = range(1, $config['max_pages']);
if ($post['op'])
clean($id);
event('post-after', $post);
buildIndex();
if (count($telegrams) > 0) {
$ids = implode(', ', array_map(function($x) { return (int)$x['id']; }, $telegrams));
query("UPDATE ``telegrams`` SET ``seen`` = 1 WHERE ``id`` IN({$ids})") or error(db_error());
die(Element('page.html', array(
// Give JS users a redirect instead of an error
if (isset($_POST['json_response'])) {
header('Content-Type: text/json');
echo json_encode(array('error' => true, 'telegram' => true));
} else {
echo Element('page.html', array(
'title' => _('Important message from Moderation'),
'config' => $config,
'body' => Element('important.html', array(
@ -1354,18 +1333,47 @@ if (isset($_POST['delete'])) {
'redirect' => $redirect,
'telegrams' => $telegrams,
))
)));
));
}
} else {
if (!isset($_POST['json_response'])) {
header('Location: ' . $redirect, true, $config['redirect_http']);
} else {
header('Content-Type: text/json; charset=utf-8');
echo json_encode(array(
'redirect' => $redirect,
'noko' => $noko,
'id' => $id
));
}
}
if ($post['op']) {
clean($id);
if ($config['try_smarter'])
$build_pages = range(1, $config['max_pages']);
}
event('post-after', $post);
// If this is a new thread or the poster is returning to the index, build it before they redirect
if ($post['op'] || !$noko)
buildIndex();
// We are already done, let's continue our heavy-lifting work in the background (if we run off FastCGI)
if (function_exists('fastcgi_finish_request'))
if (function_exists('fastcgi_finish_request')) {
@fastcgi_finish_request();
}
if ($post['op'])
if (!$post['op'] && $noko)
buildIndex();
if ($post['op']) {
rebuildThemes('post-thread', $board['uri']);
else
} else {
rebuildThemes('post', $board['uri']);
}
} elseif (isset($_POST['appeal'])) {
if (!isset($_POST['ban_id']))
error($config['error']['bot']);

Loading…
Cancel
Save