Optimization: preloading moved back to controllers
- Nearly twice faster page load - Query count greatly dropped
This commit is contained in:
parent
5a231b19c3
commit
c9a8f99f6a
7 changed files with 18 additions and 28 deletions
|
@ -24,6 +24,7 @@ class CommentController
|
|||
$pageCount = ceil($commentCount / $commentsPerPage);
|
||||
$page = max(1, min($pageCount, $page));
|
||||
$comments = Model_Comment::getEntities(null, $commentsPerPage, $page);
|
||||
R::preload($comments, ['commenter' => 'user', 'post', 'post.uploader' => 'user', 'post.sharedTag']);
|
||||
|
||||
$this->context->postGroups = true;
|
||||
$this->context->transport->paginator = new StdClass;
|
||||
|
@ -79,6 +80,8 @@ class CommentController
|
|||
public function deleteAction($id)
|
||||
{
|
||||
$comment = Model_Comment::locate($id);
|
||||
R::preload($comment, ['commenter' => 'user']);
|
||||
|
||||
PrivilegesHelper::confirmWithException(Privilege::DeleteComment, PrivilegesHelper::getIdentitySubPrivilege($comment->commenter));
|
||||
Model_Comment::remove($comment);
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ class PostController
|
|||
$pageCount = ceil($postCount / $postsPerPage);
|
||||
$page = max(1, min($pageCount, $page));
|
||||
$posts = Model_Post::getEntitiesFast($query, $postsPerPage, $page);
|
||||
R::preload($posts, 'sharedTag');
|
||||
|
||||
$this->context->transport->paginator = new StdClass;
|
||||
$this->context->transport->paginator->page = $page;
|
||||
|
@ -299,6 +300,8 @@ class PostController
|
|||
public function hideAction($id)
|
||||
{
|
||||
$post = Model_Post::locate($id);
|
||||
R::preload($post, ['uploader' => 'user']);
|
||||
|
||||
PrivilegesHelper::confirmWithException(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
||||
|
||||
if (InputHelper::get('submit'))
|
||||
|
@ -319,6 +322,8 @@ class PostController
|
|||
public function unhideAction($id)
|
||||
{
|
||||
$post = Model_Post::locate($id);
|
||||
R::preload($post, ['uploader' => 'user']);
|
||||
|
||||
PrivilegesHelper::confirmWithException(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
||||
|
||||
if (InputHelper::get('submit'))
|
||||
|
@ -339,6 +344,8 @@ class PostController
|
|||
public function deleteAction($id)
|
||||
{
|
||||
$post = Model_Post::locate($id);
|
||||
R::preload($post, ['uploader' => 'user']);
|
||||
|
||||
PrivilegesHelper::confirmWithException(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
||||
|
||||
if (InputHelper::get('submit'))
|
||||
|
@ -441,8 +448,9 @@ class PostController
|
|||
$post = Model_Post::locate($id);
|
||||
R::preload($post, [
|
||||
'tag',
|
||||
'comment',
|
||||
'uploader' => 'user',
|
||||
'ownComment.commenter' => 'user']);
|
||||
R::preload($this->context->user, ['ownFavoritee']);
|
||||
|
||||
$this->context->transport->lastSearchQuery = InputHelper::get('last-search-query');
|
||||
|
||||
|
@ -552,6 +560,9 @@ class PostController
|
|||
|
||||
private function doEdit($post, $isNew)
|
||||
{
|
||||
if (!$isNew)
|
||||
R::preload($post, ['uploader' => 'user']);
|
||||
|
||||
/* file contents */
|
||||
if (!empty($_FILES['file']['name']))
|
||||
{
|
||||
|
|
|
@ -441,6 +441,7 @@ class UserController
|
|||
$pageCount = ceil($postCount / $postsPerPage);
|
||||
$page = max(1, min($pageCount, $page));
|
||||
$posts = Model_Post::getEntities($query, $postsPerPage, $page);
|
||||
R::preload($posts, 'sharedTag');
|
||||
|
||||
$this->context->transport->tab = $tab;
|
||||
$this->context->transport->lastSearchQuery = $query;
|
||||
|
|
|
@ -81,19 +81,4 @@ abstract class AbstractModel extends RedBean_SimpleModel
|
|||
{
|
||||
R::store($entity);
|
||||
}
|
||||
|
||||
/* FUSE methods for RedBeanPHP, preventing some aliasing errors */
|
||||
public function open()
|
||||
{
|
||||
$this->preload();
|
||||
}
|
||||
|
||||
public function after_update()
|
||||
{
|
||||
$this->preload();
|
||||
}
|
||||
|
||||
public function preload()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,6 @@ class Model_Comment extends AbstractModel
|
|||
return 'Model_Comment_QueryBuilder';
|
||||
}
|
||||
|
||||
public function preload()
|
||||
{
|
||||
R::preload($this->bean, ['commenter' => 'user', 'post', 'post.uploader' => 'user']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function locate($key, $throw = true)
|
||||
|
|
|
@ -18,11 +18,6 @@ class Model_Post extends AbstractModel
|
|||
return 'Model_Post_QueryBuilder';
|
||||
}
|
||||
|
||||
public function preload()
|
||||
{
|
||||
R::preload($this->bean, ['uploader' => 'user','favoritee' => 'user']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function locate($key, $disallowNumeric = false, $throw = true)
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
$x =
|
||||
[
|
||||
'score' => $this->context->post->score,
|
||||
'comments' => $this->context->post->countOwn('comment'),
|
||||
'favs' => $this->context->post->countOwn('favoritee'),
|
||||
'comments' => $this->context->post->comment_count,
|
||||
'favs' => $this->context->post->fav_count,
|
||||
];
|
||||
?>
|
||||
<?php if (!empty($x)): ?>
|
||||
|
|
Loading…
Reference in a new issue