[Cpan-forum-commit] rev 310 - in trunk: . lib/CPAN/Forum/DB lib/CPAN/Forum/RM

svn at pti.co.il svn at pti.co.il
Thu Jul 26 20:35:26 EEST 2007


Author: gabor
Date: 2007-07-26 20:35:25 +0300 (Thu, 26 Jul 2007)
New Revision: 310

Modified:
   trunk/
   trunk/lib/CPAN/Forum/DB/Subscriptions_all.pm
   trunk/lib/CPAN/Forum/RM/Subscriptions.pm
Log:
add find() method to DB::Subscriptions_all
eliminate one more call to Class::DBI



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4330
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
   + 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4338
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752

Modified: trunk/lib/CPAN/Forum/DB/Subscriptions_all.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Subscriptions_all.pm	2007-07-25 14:48:47 UTC (rev 309)
+++ trunk/lib/CPAN/Forum/DB/Subscriptions_all.pm	2007-07-26 17:35:25 UTC (rev 310)
@@ -7,4 +7,35 @@
 __PACKAGE__->columns(All => qw/id uid allposts starters followups announcements/);
 __PACKAGE__->has_a(uid => "CPAN::Forum::DB::Users");
 
+
+
+sub find {
+    my ($self, %args) = @_;
+    my ($sql, @args) = $self->_find(%args);
+    return $self->_fetch_arrayref_of_hashes($sql, @args);
+}
+
+sub find_one {
+    my ($self, %args) = @_;
+
+    my ($sql, @args) = $self->_find(%args);
+
+    return $self->_fetch_single_hashref($sql, @args); 
+}
+
+sub _find {
+    my ($self, %args) = @_;
+
+    # check if keys of args is uid 
+    my @fields = keys %args;
+    my $where = join " AND ", map {"$_=?"} @fields;
+    my $sql = "SELECT id, allposts, starters, followups, announcements
+              FROM subscriptions_all";
+    if ($where) {
+        $sql .= " WHERE $where";
+    }
+    return ($sql, @args{@fields}); 
+}
+
+
 1;

Modified: trunk/lib/CPAN/Forum/RM/Subscriptions.pm
===================================================================
--- trunk/lib/CPAN/Forum/RM/Subscriptions.pm	2007-07-25 14:48:47 UTC (rev 309)
+++ trunk/lib/CPAN/Forum/RM/Subscriptions.pm	2007-07-26 17:35:25 UTC (rev 310)
@@ -70,14 +70,14 @@
     my ($self, $user) = @_;
 
     my @subscriptions;
-    my ($s) = CPAN::Forum::DB::Subscriptions_all->search(uid => $user->{id});
+    my $s = CPAN::Forum::DB::Subscriptions_all->find_one(uid => $user->{id}); # SQL
     $self->log->debug("all subscriptions " . ($s ? "found" : "not found"));
     push @subscriptions, {
         gid       => "_all",
         group     => "All",
-        allposts  => $s ? $s->allposts  : '',
-        starters  => $s ? $s->starters  : '',
-        followups => $s ? $s->followups : '',
+        allposts  => $s ? $s->{allposts}  : '',
+        starters  => $s ? $s->{starters}  : '',
+        followups => $s ? $s->{followups} : '',
     };
     my $gids = "_all";
 



More information about the Cpan-forum-commit mailing list