Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[fotobilder] r1437: memcache userprops, ugh

Committer: ailyin
memcache userprops, ugh
U   trunk/lib/FB/User.pm
U   trunk/lib/FotoBilder/Auth/LiveJournal.pm
Modified: trunk/lib/FB/User.pm
===================================================================
--- trunk/lib/FB/User.pm	2010-11-12 07:26:47 UTC (rev 1436)
+++ trunk/lib/FB/User.pm	2010-12-10 07:52:04 UTC (rev 1437)
@@ -30,6 +30,11 @@
     return $u->{user};
 }
 
+sub userid {
+    my ($u) = @_;
+    return $u->{'userid'};
+}
+
 # fields in object:
 #    by default, all columns from "user" table
 #
@@ -558,17 +563,29 @@
     my $ps = FB::get_props() or die;
     $u->{prop} = {};
 
-    my $sth = $u->prepare("SELECT propid, value FROM userprop WHERE userid=?",
-                          $u->{userid});
-    $sth->execute;
-    return 0 if $sth->err;
+    my $props = FB::MemCache::get('userprop:' . $u->userid);
 
-    while (my ($id, $value) = $sth->fetchrow_array) {
-        my $name = $ps->{$id};
-        next unless $name;
-        $u->{prop}{$name} = $value;
+    unless ($props) {
+        my $sth = $u->prepare(qq{
+            SELECT propid, value FROM userprop WHERE userid=?
+        }, $u->userid);
+        $sth->execute;
+
+        return 0 if $sth->err;
+
+        while (my ($id, $value) = $sth->fetchrow_array) {
+            my $name = $ps->{$id};
+            next unless $name;
+            $props->{$name} = $value;
+        }
+
+        FB::MemCache::set( 'userprop:' . $u->userid, $props );
     }
 
+    foreach my $propname ( keys %$props ) {
+        $u->{'prop'}->{$propname} = $props->{$propname};
+    }
+
     $u->{_loaded_props} = 1;
     return 1;
 }
@@ -600,6 +617,9 @@
                $u->{'userid'}, $pid) or return 0;
         delete $u->{prop}{$prop} if $u->{_loaded_props};
     }
+
+    FB::MemCache::delete('userprop:' . $u->userid);
+
     return 1;
 }
 

Modified: trunk/lib/FotoBilder/Auth/LiveJournal.pm
===================================================================
--- trunk/lib/FotoBilder/Auth/LiveJournal.pm	2010-11-12 07:26:47 UTC (rev 1436)
+++ trunk/lib/FotoBilder/Auth/LiveJournal.pm	2010-12-10 07:52:04 UTC (rev 1437)
@@ -422,6 +422,8 @@
         $u->set_prop($prop, $res{$prop});
     }
 
+    $u->set_prop( 'lj_lastsync' => time );
+
     return $u;
 }
 

Tags: andy, fotobilder, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments