Skip to content

Keep session open if messages are queued #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/Plugin/SectionLoadControllerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,31 @@ public function __construct(
GenericSession $genericSession,
array $additionalSessions = []
) {
/*
/**
* This is earliest moment where we can close the session,
* after we initialised all sessions we think will be needed
*
* Should there ever be an additional Session-type that's needed,
* nothing breaks, but the new session-type will open a new session
* and therefore block other requests
*/
$genericSession->writeClose();
$hasMessages = 0;
foreach ($additionalSessions as $session) {
if ($session instanceOf \Magento\Framework\Message\Session){
// @param \Magento\Framework\Message\Collection $messageCollection
foreach ($session->getData() as $messageCollection){
$hasMessages += count($messageCollection->getItems());
}
}
}
/**
* We've checked if there were no messages in the current session
* because the session then needs to stay open to allow the messages
* to be removed after loading them
*/
if ($hasMessages === 0 ) {
$genericSession->writeClose();
}
}

//phpcs:ignore MEQP2.Classes.PublicNonInterfaceMethods.PublicMethodFound
Expand Down