mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-12-18 18:36:00 +01:00
Performance: Use only one query for validating >>X links in posts
This commit is contained in:
parent
d7fc5adc22
commit
577a8b991d
@ -1577,20 +1577,32 @@ function markup(&$body, $track_cites = false) {
|
|||||||
$skip_chars = 0;
|
$skip_chars = 0;
|
||||||
$body_tmp = $body;
|
$body_tmp = $body;
|
||||||
|
|
||||||
|
$search_cites = array();
|
||||||
|
foreach ($cites as $matches) {
|
||||||
|
$search_cites[] = '`id` = ' . $matches[2][0];
|
||||||
|
}
|
||||||
|
$search_cites = array_unique($search_cites);
|
||||||
|
|
||||||
|
$query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' .
|
||||||
|
implode(' OR ', $search_cites), $board['uri'])) or error(db_error());
|
||||||
|
|
||||||
|
$cited_posts = array();
|
||||||
|
while ($cited = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
$cited_posts[$cited['id']] = $cited['thread'] ? $cited['thread'] : false;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($cites as $matches) {
|
foreach ($cites as $matches) {
|
||||||
$cite = $matches[2][0];
|
$cite = $matches[2][0];
|
||||||
$query = prepare(sprintf("SELECT `thread`,`id` FROM ``posts_%s`` WHERE `id` = :id LIMIT 1", $board['uri']));
|
|
||||||
$query->bindValue(':id', $cite);
|
|
||||||
$query->execute() or error(db_error($query));
|
|
||||||
|
|
||||||
// preg_match_all is not multibyte-safe
|
// preg_match_all is not multibyte-safe
|
||||||
foreach ($matches as &$match) {
|
foreach ($matches as &$match) {
|
||||||
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
|
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
if (isset($cited_posts[$cite])) {
|
||||||
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
|
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
|
||||||
$config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' .
|
$config['root'] . $board['dir'] . $config['dir']['res'] .
|
||||||
|
($cited_posts[$cite] ? $cited_posts[$cite] : $cite) . '.html#' . $cite . '">' .
|
||||||
'>>' . $cite .
|
'>>' . $cite .
|
||||||
'</a>';
|
'</a>';
|
||||||
|
|
||||||
@ -1598,7 +1610,7 @@ function markup(&$body, $track_cites = false) {
|
|||||||
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[3][0]) - mb_strlen($matches[0][0]);
|
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[3][0]) - mb_strlen($matches[0][0]);
|
||||||
|
|
||||||
if ($track_cites && $config['track_cites'])
|
if ($track_cites && $config['track_cites'])
|
||||||
$tracked_cites[] = array($board['uri'], $post['id']);
|
$tracked_cites[] = array($board['uri'], $cite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1612,6 +1624,8 @@ function markup(&$body, $track_cites = false) {
|
|||||||
$skip_chars = 0;
|
$skip_chars = 0;
|
||||||
$body_tmp = $body;
|
$body_tmp = $body;
|
||||||
|
|
||||||
|
// TODO: Make this use fewer queries, similar to local board cites.
|
||||||
|
|
||||||
foreach ($cites as $matches) {
|
foreach ($cites as $matches) {
|
||||||
$_board = $matches[2][0];
|
$_board = $matches[2][0];
|
||||||
$cite = @$matches[3][0];
|
$cite = @$matches[3][0];
|
||||||
|
Loading…
Reference in New Issue
Block a user