[Jifty-commit] r1448 - in jifty/trunk: . lib/Jifty lib/Jifty/Web

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Jul 2 23:13:38 EDT 2006


Author: alexmv
Date: Sun Jul  2 23:13:37 2006
New Revision: 1448

Added:
   jifty/trunk/lib/Jifty/Model/SessionCollection.pm
Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Everything.pm
   jifty/trunk/lib/Jifty/Web/Session.pm

Log:
 r14732 at zoq-fot-pik:  chmrr | 2006-07-02 23:13:29 -0400
  * Pull in the entire session when you load the first key.  This can
 probably be better oprimized to use an indexed query, but even this
 eliminates quite a few DB hits per page


Modified: jifty/trunk/lib/Jifty/Everything.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Everything.pm	(original)
+++ jifty/trunk/lib/Jifty/Everything.pm	Sun Jul  2 23:13:37 2006
@@ -49,6 +49,7 @@
 
 use Jifty::Model::Metadata ();
 use Jifty::Model::Session ();
+use Jifty::Model::SessionCollection ();
 
 
 use Jifty::Request ();

Added: jifty/trunk/lib/Jifty/Model/SessionCollection.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Model/SessionCollection.pm	Sun Jul  2 23:13:37 2006
@@ -0,0 +1,21 @@
+use warnings;
+use strict;
+
+package Jifty::Model::SessionCollection;
+
+use base qw/Jifty::Collection/;
+sub record_class { 'Jifty::Model::Session' }
+
+
+=head2 current_user
+
+Everyone is treated as the superuser when dealing with session
+objects.  This avoids infinite recursion, as otherwise it would try to
+look up the current user in the session object to find out who we
+are...
+
+=cut
+
+sub current_user { return Jifty::CurrentUser->superuser }
+
+1;

Modified: jifty/trunk/lib/Jifty/Web/Session.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Session.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Session.pm	Sun Jul  2 23:13:37 2006
@@ -62,6 +62,7 @@
 
     $session->create( key_type => "session" ) unless $session->id;
     $self->_session($session);
+    $self->{cache} = undef;
 }
 
 =head2 unload
@@ -109,13 +110,28 @@
 
     return undef unless $self->loaded;
 
-    my $setting = Jifty::Model::Session->new;
-    $setting->load_by_cols(
-        session_id => $self->id,
-        key_type   => $key_type,
-        data_key   => $key
-    );
-    return $setting->value;
+    if ($key_type eq "continuation" or $key_type eq "session") {
+        my $setting = Jifty::Model::Session->new;
+        $setting->load_by_cols(
+            session_id => $self->id,
+            key_type   => $key_type,
+            data_key   => $key
+        );
+        return $setting->value;
+    } else {
+        unless ($self->{cache}) {
+            my $settings = Jifty::Model::SessionCollection->new;
+            $settings->limit( column => 'session_id', value => $self->id );
+            $settings->limit( column => 'key_type',   value => 'continuation', operator => '!=', entry_aggregator => 'and' );
+            $settings->limit( column => 'key_type',   value => 'session', operator => '!=', entry_aggregator => 'and' );
+            while (my $row = $settings->next) {
+                $self->{cache}{$row->key_type}{$row->data_key} = $row->value;
+            }
+        }
+
+        return $self->{cache}{$key_type}{$key};
+    }
+
 }
 
 =head2 set KEY => VALUE, [TYPE]
@@ -153,6 +169,10 @@
             value      => $value
         );
     }
+
+    $self->{cache}{$key_type}{$key} = $value
+      if $self->{cache};
+
 }
 
 =head2 remove KEY, [TYPE]


More information about the Jifty-commit mailing list