Skip to content

Commit

Permalink
add feature to improve performances by releasing sessions when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nykopol committed Jan 25, 2019
1 parent 0303aaf commit faadccd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Controller/ElementApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function infoAction(Request $Request, $context, $type, $name){
public function renderAction(Request $Request, $context, $type, $name, $format = 'json'){
$element = $this->getElementManager()->getElement($context, $type, $name);

if($element->canReleaseSession() && $format !== 'json'){
// Release the session because whe don't write in it
$Request->getSession()->save();
}

$params = array();
if($element instanceof AbstractConfigurableElement){
$form = $this->getConfigForm($element, 'show');
Expand Down
14 changes: 14 additions & 0 deletions Model/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ public function setParameters($parameters){
$this->parameters = $parameters;
}

/**
* This method state that this element does not write in session.
* When this method return "true", the controller release the session.
* This allow concurrent requests witch improve the performances.
*
* Do not release session if you write on it like when you use forms, flashBag messages, ...
*
* @return boolean
*/
public function canReleaseSession()
{
return false;
}

}

0 comments on commit faadccd

Please sign in to comment.