Reduced page loads
- Entity of user currently logged in is kept serialized in session - Post is retrieved only if necessary in thumbnail generator
This commit is contained in:
parent
872780397d
commit
e1acb8bd99
5 changed files with 22 additions and 13 deletions
|
@ -6,7 +6,12 @@ class Bootstrap
|
|||
$this->context->loggedIn = false;
|
||||
if (isset($_SESSION['user-id']))
|
||||
{
|
||||
$this->context->user = R::findOne('user', 'id = ?', [$_SESSION['user-id']]);
|
||||
if (!isset($_SESSION['user']))
|
||||
{
|
||||
$dbUser = R::findOne('user', 'id = ?', [$_SESSION['user-id']]);
|
||||
$_SESSION['user'] = serialize($dbUser);
|
||||
}
|
||||
$this->context->user = unserialize($_SESSION['user']);
|
||||
if (!empty($this->context->user))
|
||||
{
|
||||
$this->context->loggedIn = true;
|
||||
|
|
|
@ -23,6 +23,7 @@ class AuthController
|
|||
PrivilegesHelper::confirmEmail($dbUser);
|
||||
|
||||
$_SESSION['user-id'] = $dbUser->id;
|
||||
$_SESSION['user'] = serialize($dbUser);
|
||||
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
||||
return $dbUser;
|
||||
}
|
||||
|
|
|
@ -557,19 +557,19 @@ class PostController
|
|||
|
||||
/**
|
||||
* Action that renders the thumbnail of the requested file and sends it to user.
|
||||
* @route /post/{id}/thumb
|
||||
* @route /post/{name}/thumb
|
||||
*/
|
||||
public function thumbAction($id)
|
||||
public function thumbAction($name)
|
||||
{
|
||||
$this->context->layoutName = 'layout-file';
|
||||
|
||||
$path = $this->config->main->thumbsPath . DS . $name;
|
||||
if (!file_exists($path))
|
||||
{
|
||||
$post = Model_Post::locate($id);
|
||||
|
||||
PrivilegesHelper::confirmWithException(Privilege::ViewPost);
|
||||
PrivilegesHelper::confirmWithException(Privilege::ViewPost, PostSafety::toString($post->safety));
|
||||
|
||||
$path = $this->config->main->thumbsPath . DS . $post->name;
|
||||
if (!file_exists($path))
|
||||
{
|
||||
$srcPath = $this->config->main->filesPath . DS . $post->name;
|
||||
$dstPath = $path;
|
||||
$dstWidth = $this->config->browsing->thumbWidth;
|
||||
|
@ -623,17 +623,17 @@ class PostController
|
|||
{
|
||||
$path = $this->config->main->mediaPath . DS . 'img' . DS . 'thumb.png';
|
||||
}
|
||||
|
||||
if (isset($tmpPath))
|
||||
unlink($tmpPath);
|
||||
}
|
||||
if (!is_readable($path))
|
||||
throw new SimpleException('Thumbnail file is not readable');
|
||||
|
||||
$this->context->transport->cacheDaysToLive = 30;
|
||||
$this->context->transport->mimeType = 'image/png';
|
||||
$this->context->transport->fileHash = 'thumb' . md5($post->file_hash . filemtime($path));
|
||||
$this->context->transport->fileHash = 'thumb' . md5($name . filemtime($path));
|
||||
$this->context->transport->filePath = $path;
|
||||
|
||||
if (isset($tmpPath))
|
||||
unlink($tmpPath);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -246,7 +246,10 @@ class UserController
|
|||
R::store($user);
|
||||
$this->context->transport->user = $user;
|
||||
if ($this->context->user->id == $user->id)
|
||||
{
|
||||
$this->context->user = $user;
|
||||
unset($_SESSION['user']);
|
||||
}
|
||||
$this->context->transport->success = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class="post post-type-<?php echo TextHelper::camelCaseToHumanCase(PostType::toString($this->context->post->type)) ?>">
|
||||
<a href="<?php echo \Chibi\UrlHelper::route('post', 'view', ['id' => $this->context->post->id]) ?>">
|
||||
<img class="thumb" src="<?php echo \Chibi\UrlHelper::route('post', 'thumb', ['id' => $this->context->post->id]) ?>" alt="@<?php echo $this->context->post->id ?>"/>
|
||||
<img class="thumb" src="<?php echo \Chibi\UrlHelper::route('post', 'thumb', ['name' => $this->context->post->name]) ?>" alt="@<?php echo $this->context->post->id ?>"/>
|
||||
</a>
|
||||
<div class="info-bar">
|
||||
<i class="icon-comments"></i> <span><?php echo $this->context->post->countOwn('comment') ?></span>
|
||||
|
|
Loading…
Reference in a new issue