Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #455 from shadlaws/fixes_20130711_2

Make View_Gallery::init_item() & View_Gallery::init_collection() a bit quicker.
  • Loading branch information...
commit 02878bdc809185080485b4b77ee4a8e4b9778cfd 2 parents a9f3cff + 75cf1d3
@shadlaws shadlaws authored
Showing with 23 additions and 22 deletions.
  1. +23 −22 modules/gallery/classes/Gallery/View/Gallery.php
View
45 modules/gallery/classes/Gallery/View/Gallery.php
@@ -70,29 +70,17 @@ public function init_collection() {
$this->set_global("page_size", Module::get_var("gallery", "page_size", 9));
}
- // Set "page" using the query params, if empty. No page defaults to 1.
- if (empty($this->page)) {
- $this->set_global("page", (int)Arr::get(Request::current()->query(), "page", 1));
- }
-
// Get "collection_query" from its callback.
$this->set_global("collection_query", call_user_func_array(
$this->collection_query_callback[0], $this->collection_query_callback[1]));
- // Get "children_count" before applying any order_by calls.
- $this->set_global("children_count", $this->collection_query
- ->reset(false)
- ->count_all());
-
- // Apply "collection_order_by" if set (required for search module), set as empty array if not.
- if (isset($this->collection_order_by)) {
- foreach ($this->collection_order_by as $column => $direction) {
- $this->collection_query->order_by($column, $direction);
- }
- }
-
// Redirect if "show" query parameter is set.
if ($show = Request::current()->query("show")) {
+ // Apply "collection_order_by" if set (required for search module).
+ if (isset($this->collection_order_by)) {
+ $this->collection_query->merge_order_by($this->collection_order_by);
+ }
+
$position = null;
foreach ($this->collection_query->find_all() as $key => $child) {
if ($child->id == $show) {
@@ -111,6 +99,21 @@ public function init_collection() {
HTTP::redirect($this->_paginator_url(ceil($position / $this->page_size), true));
}
+ // Set "page" using the query params, if empty. No page defaults to 1.
+ if (empty($this->page)) {
+ $this->set_global("page", (int)Arr::get(Request::current()->query(), "page", 1));
+ }
+
+ // Get "children_count" before applying any order_by calls.
+ $this->set_global("children_count", $this->collection_query
+ ->reset(false)
+ ->count_all());
+
+ // Apply "collection_order_by" if set (required for search module).
+ if (isset($this->collection_order_by)) {
+ $this->collection_query->merge_order_by($this->collection_order_by);
+ }
+
// Set "max_pages" using other params.
$this->set_global("max_pages", ceil(max($this->children_count, 1) / max($this->page_size, 1)));
@@ -189,11 +192,6 @@ public function init_item() {
// Restrict sibling query to non-albums.
$this->sibling_query->where("type", "<>", "album");
- // Get "sibling_count" before applying any order_by calls.
- $this->set_global("sibling_count", $this->sibling_query
- ->reset(false)
- ->count_all());
-
// Apply "collection_order_by" (required for search module).
foreach ($collection_order_by as $column => $direction) {
$this->sibling_query->order_by($column, $direction);
@@ -204,6 +202,9 @@ public function init_item() {
->reset(false)
->find_all());
+ // Get "sibling_count" (since siblings are found without limit or offset, just count them).
+ $this->set_global("sibling_count", count($this->siblings));
+
// Get "position" of the item within its siblings (1-indexed).
foreach ($this->siblings as $key => $sibling) {
if ($sibling->id == $this->item->id) {
Please sign in to comment.
Something went wrong with that request. Please try again.