Skip to content

Commit

Permalink
improved overall performance by deserializing sessions only on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 27, 2014
1 parent c24e48a commit 350478b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

5.67 2014-11-27
- Improved overall performance by deserializing sessions only on demand.
- Fixed bug where embedded applications would deserialize sessions twice.

5.66 2014-11-26
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojolicious.pm
Expand Up @@ -89,8 +89,6 @@ sub defaults { Mojo::Util::_stash(defaults => @_) }
sub dispatch {
my ($self, $c) = @_;

my $stash = $c->stash;
$self->sessions->load($c) unless exists $stash->{'mojo.active_session'};
my $plugins = $self->plugins->emit_hook(before_dispatch => $c);

# Try to find a static file
Expand All @@ -99,6 +97,7 @@ sub dispatch {
unless $tx->res->code;

# Start timer (ignore static files)
my $stash = $c->stash;
unless ($stash->{'mojo.static'} || $stash->{'mojo.started'}) {
my $req = $c->req;
my $method = $req->method;
Expand Down
6 changes: 5 additions & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -255,8 +255,12 @@ sub send {
sub session {
my $self = shift;

my $stash = $self->stash;
$self->app->sessions->load($self)
unless exists $stash->{'mojo.active_session'};

# Hash
my $session = $self->stash->{'mojo.session'} ||= {};
my $session = $stash->{'mojo.session'} ||= {};
return $session unless @_;

# Get
Expand Down
1 change: 0 additions & 1 deletion lib/Mojolicious/Sessions.pm
Expand Up @@ -14,7 +14,6 @@ has serialize => sub { \&Mojo::JSON::encode_json };
sub load {
my ($self, $c) = @_;

return unless $c->req->headers->cookie;
return unless my $value = $c->signed_cookie($self->cookie_name);
$value =~ y/-/=/;
return unless my $session = $self->deserialize->(b64_decode $value);
Expand Down

0 comments on commit 350478b

Please sign in to comment.