summaryrefslogtreecommitdiff
path: root/inc/functions.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2015-03-10 13:42:10 +0100
committerczaks <marcin@6irc.net>2015-03-10 13:42:10 +0100
commit7623de9e2fe8424f35be70cddb9cf68254e49e3e (patch)
tree7ad20254909dc4eb87ab32902ac751f217e0e65d /inc/functions.php
parent4aa1d387f8a90d33207d28afc637958759e2ce6e (diff)
... (cache)
Diffstat (limited to 'inc/functions.php')
-rwxr-xr-xinc/functions.php21
1 files changed, 15 insertions, 6 deletions
diff --git a/inc/functions.php b/inc/functions.php
index 846dbdaa..6880ad44 100755
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2479,16 +2479,25 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false)
$slug = false;
if ($config['slugify'] && isset($post['thread']) && $post['thread']) {
+ $cvar = "slug_".$b['uri']."_".$id;
if (!$thread) {
- // Oh fuck, we'd better optimize it ASAP
+ $slug = Cache::get($cvar);
- $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri']));
- $query->bindValue(':id', $id, PDO::PARAM_INT);
- $query->execute() or error(db_error($query));
+ if ($slug === false) {
+ $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri']));
+ $query->bindValue(':id', $id, PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
- $thread = $query->fetch(PDO::FETCH_ASSOC);
+ $thread = $query->fetch(PDO::FETCH_ASSOC);
+
+ $slug = $thread['slug'];
+
+ Cache::set($cvar, $slug);
+ }
+ }
+ else {
+ $slug = $thread['slug'];
}
- $slug = $thread['slug'];
}
elseif ($config['slugify']) {
$slug = $post['slug'];