vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r17962: LJSUP-7646: do not cache db connection i...

Committer: vsukhanov
LJSUP-7646: do not cache db connection in LJ::User object. DBI::Role's cache is enough.
U   trunk/cgi-bin/LJ/User.pm
Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2010-12-17 08:29:46 UTC (rev 17961)
+++ trunk/cgi-bin/LJ/User.pm	2010-12-17 08:43:46 UTC (rev 17962)
@@ -388,7 +388,8 @@
 # user is writable, else 0
 sub writer {
     my $u = shift;
-    return LJ::get_cluster_master($u) || 0;
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u);
+    return $dbcm || 0;
 }
 
 sub userpic {
@@ -585,7 +586,7 @@
     return $LJ::CACHE_CLUSTER_IS_INNO{$u->{clusterid}}
     if defined $LJ::CACHE_CLUSTER_IS_INNO{$u->{clusterid}};
 
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
     my (undef, $ctable) = $dbcm->selectrow_array("SHOW CREATE TABLE log2");
     die "Failed to auto-discover database type for cluster \#$u->{clusterid}: [$ctable]"
@@ -599,7 +600,7 @@
     my $u = shift;
     return 1 unless $u->is_innodb;
 
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $rv = $dbcm->begin_work;
@@ -613,7 +614,7 @@
     my $u = shift;
     return 1 unless $u->is_innodb;
 
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $rv = $dbcm->commit;
@@ -627,7 +628,7 @@
     my $u = shift;
     return 1 unless $u->is_innodb;
 
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $rv = $dbcm->rollback;
@@ -641,7 +642,7 @@
 sub prepare {
     my $u = shift;
 
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $rv = $dbcm->prepare(@_);
@@ -659,7 +660,7 @@
     my $uid = $u->{userid}+0
         or croak "Database update called on null user object";
 
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     $query =~ s!^(\s*\w+\s+)!$1/* uid=$uid */ !;
@@ -676,7 +677,7 @@
 
 sub selectrow_array {
     my $u = shift;
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $set_err = sub {
@@ -698,7 +699,7 @@
 
 sub selectcol_arrayref {
     my $u = shift;
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $rv = $dbcm->selectcol_arrayref(@_);
@@ -713,7 +714,7 @@
 
 sub selectall_hashref {
     my $u = shift;
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $rv = $dbcm->selectall_hashref(@_);
@@ -727,7 +728,7 @@
 
 sub selectall_arrayref {
     my $u = shift;
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $rv = $dbcm->selectall_arrayref(@_);
@@ -741,7 +742,7 @@
 
 sub selectrow_hashref {
     my $u = shift;
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     my $rv = $dbcm->selectrow_hashref(@_);
@@ -767,7 +768,7 @@
     my $u = shift;
     my $text = shift;
 
-    my $dbcm = $u->{'_dbcm'} ||= LJ::get_cluster_master($u)
+    my $dbcm = $u->{'_dbcm'} || LJ::get_cluster_master($u)
         or croak $u->nodb_err;
 
     return $dbcm->quote($text);
@@ -1185,7 +1186,7 @@
     return undef unless $nodeid =~ /^\d+$/;
     return undef unless $u->writer;
 
-    my $dbcm = $u->{_dbcm};
+    my $dbcm = $u->writer;
 
     my $memkey = [$u->{'userid'}, "talk2:$u->{'userid'}:$nodetype:$nodeid"];
     my $lockkey = $memkey->[1];
@@ -1211,7 +1212,7 @@
     my ($u, $errref, $sql, @args) = @_;
     return undef unless $u->writer;
 
-    my $dbcm = $u->{_dbcm};
+    my $dbcm = $u->writer;
 
     my $memkey = [$u->{'userid'}, "log2lt:$u->{'userid'}"];
     my $lockkey = $memkey->[1];

Tags: livejournal, pm, vadvs
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