Advertisement
Guest User

Untitled

a guest
May 4th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. diff --git a/app/Tygh/BlockManager/Location.php b/app/Tygh/BlockManager/Location.php
  2. index 5ac7b3b..af573d7 100644
  3. --- a/app/Tygh/BlockManager/Location.php
  4. +++ b/app/Tygh/BlockManager/Location.php
  5. @@ -24,6 +24,9 @@ class Location
  6. private static $_instance;
  7. private $_layout_id = 0;
  8.  
  9. + /** @var array Locations cached by dispatch */
  10. + private static $dispatch_cache;
  11. +
  12. /**
  13. * Gets list of locations
  14. *
  15. @@ -121,30 +124,41 @@ class Location
  16. */
  17. fn_set_hook('get_location_pre', $dispatch, $lang_code);
  18.  
  19. - $dispatch = explode('.', $dispatch);
  20. + $cache_key = $dispatch;
  21. + if (!empty($dynamic_object)) {
  22. + $cache_key .= "_{$dynamic_object['object_type']}_{$dynamic_object['object_id']}";
  23. + }
  24.  
  25. - $location = array();
  26. - while (count($dispatch) > 0) {
  27. - // Try to get location for this dispatch
  28. - $locations = $this->getList(array(
  29. - 'dispatch' => implode('.', $dispatch),
  30. - 'dynamic_object' => $dynamic_object,
  31. - 'sort_by' => 'object_ids',
  32. - 'sort_order' => 'desc',
  33. - 'limit' => 1
  34. - ));
  35. + if (isset(self::$dispatch_cache[$cache_key])) {
  36. + $location = self::$dispatch_cache[$cache_key];
  37. + } else {
  38. + $dispatch = explode('.', $dispatch);
  39. +
  40. + $location = array();
  41. + while (count($dispatch) > 0) {
  42. + // Try to get location for this dispatch
  43. + $locations = $this->getList(array(
  44. + 'dispatch' => implode('.', $dispatch),
  45. + 'dynamic_object' => $dynamic_object,
  46. + 'sort_by' => 'object_ids',
  47. + 'sort_order' => 'desc',
  48. + 'limit' => 1
  49. + ));
  50. +
  51. + if (!empty($locations)) {
  52. + $location = array_pop($locations);
  53. + break;
  54. + } else {
  55. + array_pop($dispatch);
  56. + }
  57. + }
  58.  
  59. - if (!empty($locations)) {
  60. - $location = array_pop($locations);
  61. - break;
  62. - } else {
  63. - array_pop($dispatch);
  64. + // Get default location if there is no location for this dispatch
  65. + if (empty($location)) {
  66. + $location = $this->getDefault($lang_code);
  67. }
  68. - }
  69.  
  70. - // Get default location if there is no location for this dispatch
  71. - if (empty($location)) {
  72. - $location = $this->getDefault($lang_code);
  73. + self::$dispatch_cache[$cache_key] = $location;
  74. }
  75.  
  76. /**
  77. @@ -223,7 +237,7 @@ class Location
  78. * )</pre>
  79. *
  80. * @param array $location_data Array of location data
  81. - * @param string $lang_code language code
  82. + * @param string $lang_code language code
  83. * @return int Location id if new location was created, DB result otherwise
  84. */
  85. public function update($location_data, $lang_code = DESCR_SL)
  86. @@ -431,8 +445,8 @@ class Location
  87. *
  88. * @param int $location_id Location identifier
  89. * @param array $description Array of description data
  90. - * @param string $lang_code language code
  91. - * @return bool True in success, false otherwise
  92. + * @param string $lang_code language code
  93. + * @return bool True in success, false otherwise
  94. */
  95. private function _updateDescription($location_id, $description, $lang_code = DESCR_SL)
  96. {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement