[Cpan-forum-commit] rev 327 - in trunk: . lib/CPAN lib/CPAN/Forum/DB
svn at pti.co.il
svn at pti.co.il
Fri Aug 10 18:34:15 EEST 2007
Author: gabor
Date: 2007-08-10 18:34:15 +0300 (Fri, 10 Aug 2007)
New Revision: 327
Modified:
trunk/
trunk/lib/CPAN/Forum.pm
trunk/lib/CPAN/Forum/DB/Posts.pm
trunk/lib/CPAN/Forum/DB/Subscriptions.pm
Log:
replace the subscriptions list fetch for followups by get_subscriptsion of
DB::Subscriptions
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4395
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
+ 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4396
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
Modified: trunk/lib/CPAN/Forum/DB/Posts.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Posts.pm 2007-08-10 15:33:57 UTC (rev 326)
+++ trunk/lib/CPAN/Forum/DB/Posts.pm 2007-08-10 15:34:15 UTC (rev 327)
@@ -205,6 +205,11 @@
return $post_id;
}
+sub list_uids_who_posted_in_thread {
+ my ($self, $thread) = @_;
+ my $sql = "SELECT DISTINCT uid FROM posts WHERE thread=?";
+ return $self->_select_column($sql, $thread);
+}
1;
Modified: trunk/lib/CPAN/Forum/DB/Subscriptions.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Subscriptions.pm 2007-08-10 15:33:57 UTC (rev 326)
+++ trunk/lib/CPAN/Forum/DB/Subscriptions.pm 2007-08-10 15:34:15 UTC (rev 327)
@@ -45,7 +45,7 @@
sub get_subscriptions {
my ($self, $field, $gid, $pauseid) = @_;
- if (not grep {$field eq $_} qw(allposts)) {
+ if (not grep {$field eq $_} qw(allposts starters followups)) {
Carp::croak("Invalid field '$field'");
}
@@ -53,15 +53,15 @@
# People who asked for all the posts in this group
# People who asked for all the posts in this PAUSEID
- my $sql = " SELECT DISTINCT username, email
+ my $sql = " SELECT DISTINCT username, email, users.id id
FROM users, subscriptions_all
WHERE (users.id=subscriptions_all.uid AND subscriptions_all.$field=1)
UNION
- SELECT DISTINCT username, email
+ SELECT DISTINCT username, email, users.id id
FROM users, subscriptions
WHERE (users.id=subscriptions.uid AND subscriptions.$field=1 AND gid=?)
UNION
- SELECT DISTINCT username, email
+ SELECT DISTINCT username, email, users.id id
FROM users, subscriptions_pauseid
WHERE
(users.id=subscriptions_pauseid.uid
Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm 2007-08-10 15:33:57 UTC (rev 326)
+++ trunk/lib/CPAN/Forum.pm 2007-08-10 15:34:15 UTC (rev 327)
@@ -1431,64 +1431,38 @@
my %to; # keys are e-mail addresses that have already received an e-mail
- # subscriptions to "all" messages in the current group
$self->log->debug("Processing messages for allposts");
-
-
my $users = CPAN::Forum::DB::Subscriptions->get_subscriptions('allposts', $post->{gid}, $post->{pauseid}); # SQL
$self->_sendmail($users, $mail, \%to);
- my $it;
if ($post->{thread} == $post->{id}) {
$self->log->debug("Processing messages for thread starter");
+ my $users = CPAN::Forum::DB::Subscriptions->get_subscriptions('starters', $post->{gid}, $post->{pauseid}); # SQL
+ $self->_sendmail($users, $mail, \%to);
+ } else {
+ $self->log->debug("Processing messages for followups, users who posted in this thread");
- # People who are subscribed to all thread starters
- $it = CPAN::Forum::DB::Subscriptions_all->search(starters => 1);
- $self->_sendmail($it, $mail, \%to);
-
- # People who are subscribed to the thread startes in this group
- $it = CPAN::Forum::DB::Subscriptions->search(starters => 1, gid => $post->{gid});
- $self->_sendmail($it, $mail, \%to);
-
- # People who are subscribed to the thread startes of this PAUSEID
- $it = CPAN::Forum::DB::Subscriptions_pauseid->search(starters => 1, pauseid => $post->{pauseid});
- $self->_sendmail($it, $mail, \%to);
+ my $uids = CPAN::Forum::DB::Posts->list_uids_who_posted_in_thread($post->{thread});
+ $self->log->debug(Data::Dumper->Dump([$uids], ['uids']));
+ my %uids = map {{ $_ => 1 }} @$uids;
+
+ my $users = CPAN::Forum::DB::Subscriptions->get_subscriptions('followups', $post->{gid}, $post->{pauseid}); # SQL
+ my @users_who_posted = grep { !$uids{ $_->{id} } } @$users;
+ $self->_sendmail(\@users_who_posted, $mail, \%to);
}
- else {
- $self->log->debug("Processing messages for followups");
-
- # Collect the users who posted in this thread
- my %uids;
- my $pit = CPAN::Forum::DB::Posts->search(thread => $post->{thread});
- while (my $p = $pit->next) {
- $uids{$p->uid}=1;
- $self->log->debug("Ids: " . $p->uid);
- }
-
- $it = CPAN::Forum::DB::Subscriptions_all->search(followups => 1);
- $self->_sendmail($it, $mail, \%to, \%uids);
-
- $it = CPAN::Forum::DB::Subscriptions->search(followups => 1, gid => $post->{gid});
- $self->_sendmail($it, $mail, \%to, \%uids);
-
- $it = CPAN::Forum::DB::Subscriptions_pauseid->search(followups => 1, pauseid => $post->{pauseid});
- $self->_sendmail($it, $mail, \%to);
- }
-
+
$self->log->debug("Number of e-mails sent: ", scalar keys %to);
}
sub _sendmail {
- my ($self, $users, $mail, $to, $uids) = @_;
+ my ($self, $users, $mail, $to) = @_;
foreach my $user (@$users) {
#$self->log->debug(Data::Dumper->Dump([$mail], ['mail']));
my $email = $user->{email};
$mail->{To} = $email;
- $self->log->debug("Processing uid: " . $user->{username}) if $uids;
- next if $uids and not $uids->{$user->{username}};
$self->log->debug("Sending to $email id was found");
- next if $_[3]->{$email}++; #TODO: stop using hardcoded reference to position!!!!!
+ next if $to->{$email}++; #TODO: stop using hardcoded reference to position!!!!!
$self->log->debug("Sending to $email first time sending");
$self->_my_sendmail(%$mail);
$self->log->debug("Sent to $email");
More information about the Cpan-forum-commit
mailing list