Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/app/Tygh/BlockManager/Location.php b/app/Tygh/BlockManager/Location.php
- index 5ac7b3b..af573d7 100644
- --- a/app/Tygh/BlockManager/Location.php
- +++ b/app/Tygh/BlockManager/Location.php
- @@ -24,6 +24,9 @@ class Location
- private static $_instance;
- private $_layout_id = 0;
- + /** @var array Locations cached by dispatch */
- + private static $dispatch_cache;
- +
- /**
- * Gets list of locations
- *
- @@ -121,30 +124,41 @@ class Location
- */
- fn_set_hook('get_location_pre', $dispatch, $lang_code);
- - $dispatch = explode('.', $dispatch);
- + $cache_key = $dispatch;
- + if (!empty($dynamic_object)) {
- + $cache_key .= "_{$dynamic_object['object_type']}_{$dynamic_object['object_id']}";
- + }
- - $location = array();
- - while (count($dispatch) > 0) {
- - // Try to get location for this dispatch
- - $locations = $this->getList(array(
- - 'dispatch' => implode('.', $dispatch),
- - 'dynamic_object' => $dynamic_object,
- - 'sort_by' => 'object_ids',
- - 'sort_order' => 'desc',
- - 'limit' => 1
- - ));
- + if (isset(self::$dispatch_cache[$cache_key])) {
- + $location = self::$dispatch_cache[$cache_key];
- + } else {
- + $dispatch = explode('.', $dispatch);
- +
- + $location = array();
- + while (count($dispatch) > 0) {
- + // Try to get location for this dispatch
- + $locations = $this->getList(array(
- + 'dispatch' => implode('.', $dispatch),
- + 'dynamic_object' => $dynamic_object,
- + 'sort_by' => 'object_ids',
- + 'sort_order' => 'desc',
- + 'limit' => 1
- + ));
- +
- + if (!empty($locations)) {
- + $location = array_pop($locations);
- + break;
- + } else {
- + array_pop($dispatch);
- + }
- + }
- - if (!empty($locations)) {
- - $location = array_pop($locations);
- - break;
- - } else {
- - array_pop($dispatch);
- + // Get default location if there is no location for this dispatch
- + if (empty($location)) {
- + $location = $this->getDefault($lang_code);
- }
- - }
- - // Get default location if there is no location for this dispatch
- - if (empty($location)) {
- - $location = $this->getDefault($lang_code);
- + self::$dispatch_cache[$cache_key] = $location;
- }
- /**
- @@ -223,7 +237,7 @@ class Location
- * )</pre>
- *
- * @param array $location_data Array of location data
- - * @param string $lang_code language code
- + * @param string $lang_code language code
- * @return int Location id if new location was created, DB result otherwise
- */
- public function update($location_data, $lang_code = DESCR_SL)
- @@ -431,8 +445,8 @@ class Location
- *
- * @param int $location_id Location identifier
- * @param array $description Array of description data
- - * @param string $lang_code language code
- - * @return bool True in success, false otherwise
- + * @param string $lang_code language code
- + * @return bool True in success, false otherwise
- */
- private function _updateDescription($location_id, $description, $lang_code = DESCR_SL)
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement