Commit aa2786b477ea6efaba974cbd72458a888455b2d1
1 parent
2b73f0c5
Exists in
master
and in
95 other branches
Opimization around makeLocalTree and makeRemoteTree (#7169 & #7170)
Showing
2 changed files
with
55 additions
and
18 deletions
Show diff stats
php/classes/UserMgr.php
... | ... | @@ -22,6 +22,7 @@ class UserMgr |
22 | 22 | 'USERWORKINGDIR' =>'RES', 'USERTTDIR' => 'TT', 'USERJOBDIR' => 'JOBS', |
23 | 23 | 'USERTEMPDIR' => 'TEMP'); |
24 | 24 | protected $userGrps; |
25 | + protected $userGrpsCheckSum; //use to know if there is a modification in user groups | |
25 | 26 | protected $amdaClient; //client to dd webservice |
26 | 27 | protected $paramMgr, $baseExtXml; |
27 | 28 | |
... | ... | @@ -136,14 +137,18 @@ class UserMgr |
136 | 137 | return true; |
137 | 138 | } |
138 | 139 | |
139 | - protected function getUserGrps() | |
140 | + protected function loadUserGrps() | |
140 | 141 | { |
142 | + if (isset($this->userGrps)) { | |
143 | + return; | |
144 | + } | |
141 | 145 | $info = $this->amdaClient->getUserInfo($this->user); |
142 | - | |
143 | - if (empty($info['group'])) | |
144 | - return null; | |
145 | - else | |
146 | - return explode(',',$info['group']); | |
146 | + | |
147 | + $this->userGrpsCheckSum = ''; | |
148 | + if (!empty($info['group'])) { | |
149 | + $this->userGrpsCheckSum = md5($info['group']); | |
150 | + $this->userGrps = explode(',',$info['group']); | |
151 | + } | |
147 | 152 | } |
148 | 153 | |
149 | 154 | /* |
... | ... | @@ -152,6 +157,9 @@ class UserMgr |
152 | 157 | */ |
153 | 158 | protected function isSpecialGroup() |
154 | 159 | { |
160 | + if (!isset($this->userGrps)) | |
161 | + return NULL; | |
162 | + | |
155 | 163 | $specialGrps = new DomDocument("1.0"); |
156 | 164 | |
157 | 165 | if (!($specialGrps->load(specialGrpsXml))) return null; |
... | ... | @@ -259,7 +267,13 @@ class UserMgr |
259 | 267 | foreach ($basesWS as $base) |
260 | 268 | { |
261 | 269 | $baseId = $base->getAttribute('xml:id'); |
262 | - | |
270 | + $lastModif = $base->getAttribute('lastModif'); | |
271 | + if (!empty($lastModif)) { | |
272 | + $lastModif = intval($lastModif); | |
273 | + if (($lastModif > 0) && ((time() - $lastModif) < REMOTE_PARAMS_UPDATE_DELAY)) { | |
274 | + continue; | |
275 | + } | |
276 | + } | |
263 | 277 | if (!$this->baseExtXml->load(RemoteData.$baseId.'/base.xml')) |
264 | 278 | { |
265 | 279 | $base->setAttribute("desc","ATTENTION!!! This DataCenter DOES NOT EXIST ANY MORE!!! Remove it from your tree"); |
... | ... | @@ -270,6 +284,7 @@ class UserMgr |
270 | 284 | } |
271 | 285 | |
272 | 286 | if ($base->hasAttribute('addable')) { |
287 | + $base->setAttribute('lastModif', time()); | |
273 | 288 | // keep this base tree |
274 | 289 | // error_log($baseId,1,email); |
275 | 290 | } |
... | ... | @@ -294,6 +309,8 @@ class UserMgr |
294 | 309 | |
295 | 310 | $centerNode->setAttribute('name', $base->getAttribute('name')); |
296 | 311 | $centerNode->setAttribute('desc', $base->getAttribute('desc')); |
312 | + $centerNode->setAttribute('lastModif', time()); | |
313 | + | |
297 | 314 | |
298 | 315 | $base->parentNode->removeChild($base); |
299 | 316 | |
... | ... | @@ -355,7 +372,7 @@ class UserMgr |
355 | 372 | $this->paramMgr->xmlDom->appendChild($BASE); |
356 | 373 | |
357 | 374 | return $this->paramMgr->xmlDom->save($this->paramMgr->xmlName); |
358 | - } | |
375 | + } | |
359 | 376 | } |
360 | 377 | |
361 | 378 | protected function makeNewBase($baseId) |
... | ... | @@ -546,8 +563,6 @@ class UserMgr |
546 | 563 | |
547 | 564 | $this->setPath(); |
548 | 565 | |
549 | - $this->userGrps = $this->getUserGrps(); | |
550 | - | |
551 | 566 | if (!$this->makeLocalTree()) |
552 | 567 | die("Login for ".$this->user." failed: Can't make LocalParams.xml");; |
553 | 568 | |
... | ... | @@ -568,7 +583,7 @@ class UserMgr |
568 | 583 | /* |
569 | 584 | * Special groups are defined in the generic_data/SpecialSettings/Groups.xml |
570 | 585 | */ |
571 | - if ($this->userGrps) { | |
586 | + if (isset($this->userGrps)) { | |
572 | 587 | // $specialGroup = $this->isSpecialGroup(); |
573 | 588 | $specialGroup = false; |
574 | 589 | // Special Info for special groups |
... | ... | @@ -602,20 +617,40 @@ class UserMgr |
602 | 617 | |
603 | 618 | protected function makeLocalTree() |
604 | 619 | { |
605 | - if (file_exists(USERWSDIR.'LocalParams.xml')) | |
606 | - unlink(USERWSDIR.'LocalParams.xml'); | |
620 | + $this->loadUserGrps(); | |
621 | + | |
622 | + if (file_exists(USERWSDIR.'LocalParams.xml')) { | |
623 | + if (file_exists(USERWSDIR.'userGrpsChecksum')) { | |
624 | + $lastGrpsChecksum = file_get_contents(USERWSDIR.'userGrpsChecksum'); | |
625 | + if ($lastGrpsChecksum == $this->userGrpsCheckSum) { | |
626 | + //No modification in groups for this user | |
627 | + if (filemtime(USERWSDIR.'LocalParams.xml') == filemtime(LocalData.'/LocalParams.xml')) { | |
628 | + //And no modification in LocalParams file => skip makeLocalTree | |
629 | + return true; | |
630 | + } | |
631 | + } | |
632 | + } | |
633 | + unlink(USERWSDIR.'LocalParams.xml'); | |
634 | + } | |
607 | 635 | |
608 | 636 | if (!copy(LocalData.'/LocalParams.xml', USERWSDIR.'LocalParams.xml')) |
609 | - die("Login for ".$this->user." failed: Can't copy LocalParams.xml"); | |
610 | - | |
611 | - if ($this->userGrps) | |
612 | - return $this->updateTreeForGrps(USERWSDIR.'LocalParams.xml'); | |
637 | + die("Login for ".$this->user." failed: Can't copy LocalParams.xml"); | |
638 | + //Save groups checksum used to generate this user local tree | |
639 | + file_put_contents(USERWSDIR.'userGrpsChecksum', $this->userGrpsCheckSum); | |
613 | 640 | |
614 | - return true; | |
641 | + $result = $this->updateTreeForGrps(USERWSDIR.'LocalParams.xml'); | |
642 | + | |
643 | + //Set modif time to the original one | |
644 | + touch(USERWSDIR.'LocalParams.xml', filemtime(LocalData.'/LocalParams.xml')); | |
645 | + | |
646 | + return TRUE; | |
615 | 647 | } |
616 | 648 | |
617 | 649 | protected function updateTreeForGrps($file) |
618 | 650 | { |
651 | + if (!isset($this->userGrps)) | |
652 | + return TRUE; | |
653 | + | |
619 | 654 | $xml = new DomDocument("1.0"); |
620 | 655 | |
621 | 656 | if(!$xml->load($file)) |
... | ... |
php/config.php
... | ... | @@ -66,6 +66,8 @@ ini_set('user_agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:7.0) Gecko/201 |
66 | 66 | // ini_set('upload_max_filesize',100000000); |
67 | 67 | // ini_set('post_max_size',1050000000); |
68 | 68 | |
69 | +// Delay between two update of remote parameters (in sec.) | |
70 | +define('REMOTE_PARAMS_UPDATE_DELAY', 3600); | |
69 | 71 | |
70 | 72 | // General Info dirs |
71 | 73 | define('DATAPATH', IHM_SRC_DIR.'/generic_data/'); |
... | ... |