forked from fballiano/magento-cache-regeneration-lock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fballiano-magento-cache-regeneration-lock.patch
66 lines (63 loc) · 2.87 KB
/
fballiano-magento-cache-regeneration-lock.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From 51dd4b477b7cd11482bcd7bf5334d5825bfb05fa Mon Sep 17 00:00:00 2001
From: Fabrizio Balliano <[email protected]>
Date: Tue, 5 Jan 2016 11:26:42 +0000
Subject: [PATCH] added enterprise support
---
app/code/local/Mage/Core/Model/App.php | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/app/code/local/Mage/Core/Model/App.php b/app/code/local/Mage/Core/Model/App.php
index 56f5765..552935d 100644
--- a/app/code/local/Mage/Core/Model/App.php
+++ b/app/code/local/Mage/Core/Model/App.php
@@ -422,6 +422,38 @@ class Mage_Core_Model_App
protected function _initModules()
{
if (!$this->_config->loadModulesCache()) {
+ //FBALLIANO CACHE GENERATION LOCK START
+ if (Mage::getEdition() == Mage::EDITION_ENTERPRISE) {
+ $resource = new Enterprise_Index_Model_Resource_Lock_Resource();
+ $connection = $resource->getConnection('enterprise_index_write', 'default_lock');
+ $lock = new Enterprise_Index_Model_Resource_Helper_Mysql4("enterprise_index");
+ } else {
+ $resource = new Mage_Index_Model_Resource_Lock_Resource();
+ $connection = $resource->getConnection('index_write', 'default_lock');
+ $lock = new Mage_Index_Model_Resource_Helper_Mysql4("index");
+ }
+ $lock->setWriteAdapter($connection);
+ $loopcounter = 0;
+ while (true) {
+ //try to get the lock. failure means someone else holds the lock
+ if ($lock->setLock("fballiano_cache_regeneration")) {
+ //perhaps someone else was building cache content while we waited for the lock
+ //lets see if we can load anything
+ if ($this->_config->loadModulesCache()) {
+ $lock->releaseLock("fballiano_cache_regeneration");
+ return $this;
+ }
+
+ //cache was empty or corrupt. proceed to building the cache content
+ break;
+ }
+ if ($loopcounter++ > 20) {
+ header("504 Gateway Timeout", true, 504);
+ die();
+ }
+ }
+ //FBALLIANO CACHE GENERATION LOCK END
+
$this->_config->loadModules();
if ($this->_config->isLocalConfigLoaded() && !$this->_shouldSkipProcessModulesUpdates()) {
Varien_Profiler::start('mage::app::init::apply_db_schema_updates');
@@ -430,6 +462,10 @@ class Mage_Core_Model_App
}
$this->_config->loadDb();
$this->_config->saveCache();
+
+ //FBALLIANO CACHE GENERATION LOCK START
+ $lock->releaseLock("fballiano_cache_regeneration");
+ //FBALLIANO CACHE GENERATION LOCK END
}
return $this;
}
--
2.6.1