Patch by mark. 

diffs (223 lines):

diff -r 7a377ed2f65e -r b8b7f42b8a41 bin/upgrading/update-db-general.pl
--- a/bin/upgrading/update-db-general.pl        Sat Oct 03 15:27:21 2009 +0000
+++ b/bin/upgrading/update-db-general.pl        Sun Oct 04 00:47:02 2009 +0000
@@ -1251,6 +1251,7 @@ CREATE TABLE syndicated_hubbub2 (
     verifytoken VARCHAR(64) NOT NULL,
     lastseenat INT UNSIGNED NOT NULL,
     leasegoodto INT UNSIGNED,
+    timespinged INT UNSIGNED NOT NULL DEFAULT '0',
 
     UNIQUE (userid, huburl, topicurl),
     UNIQUE (verifytoken),
@@ -3788,6 +3789,11 @@ register_alter(sub {
                   q{ALTER TABLE import_data ADD COLUMN usejournal VARCHAR(255) 
AFTER username} );
     }
 
+    unless ( column_type( 'syndicated_hubbub2', 'timespinged' ) ) {
+        do_alter( 'syndicated_hubbub2',
+                  q{ALTER TABLE syndicated_hubbub2 ADD COLUMN timespinged INT 
UNSIGNED NOT NULL DEFAULT '0'} );
+    }
+
 });
 
 
diff -r 7a377ed2f65e -r b8b7f42b8a41 cgi-bin/DW/Logic/ProfilePage.pm
--- a/cgi-bin/DW/Logic/ProfilePage.pm   Sat Oct 03 15:27:21 2009 +0000
+++ b/cgi-bin/DW/Logic/ProfilePage.pm   Sun Oct 04 00:47:02 2009 +0000
@@ -302,6 +302,33 @@ sub userpic_stats {
 }
 
 
+# returns the account's PubSubHubbub information
+# available only for syndication account types
+sub hubbub_info_rows {
+    my $self = $_[0];
+
+    my $u = $self->{u};
+    return () unless $u->is_syndicated && LJ::is_enabled( 'hubbub' );
+
+    # FIXME: should probably have a PubSubHubbub module that gets this sort
+    # of thing so we don't have to scatter SQL in the profile logic...
+    my $dbr = LJ::get_db_reader();
+
+    # for each subscription we have active, return a hash of the information
+    my $subs = $dbr->selectall_hashref(
+        q{SELECT id, userid, huburl, topicurl, UNIX_TIMESTAMP() - lastseenat 
AS 'lastseen',
+                 leasegoodto, timespinged
+          FROM syndicated_hubbub2
+          WHERE userid = ?},
+        'id', undef, $u->id
+    );
+    return () if $dbr->err;
+
+    # return this as an array sorted by id (just keeps it stable)
+    return sort { $a->{id} <=> $b->{id} } values %{ $subs || {} };
+}
+
+
 # returns array of hashrefs
 sub basic_info_rows {
     my $self = $_[0];
@@ -553,10 +580,9 @@ sub _basic_info_syn_status {
     my $self = $_[0];
 
     my $u = $self->{u};
+    return () unless $u->is_syndicated;
+
     my $ret = [];
-
-    return $ret unless $u->is_syndicated;
-
     my $synd = $u->get_syndicated;
     my $syn_status;
 
@@ -591,10 +617,9 @@ sub _basic_info_syn_readers {
     my $self = $_[0];
 
     my $u = $self->{u};
+    return () unless $u->is_syndicated;
+
     my $ret = [];
-
-    return $ret unless $u->is_syndicated;
-
     $ret->[0] = LJ::Lang::ml( '.label.syndreadcount' );
     $ret->[1] = scalar $u->watched_by_userids;
 
diff -r 7a377ed2f65e -r b8b7f42b8a41 cgi-bin/LJ/SynSuck.pm
--- a/cgi-bin/LJ/SynSuck.pm     Sat Oct 03 15:27:21 2009 +0000
+++ b/cgi-bin/LJ/SynSuck.pm     Sun Oct 04 00:47:02 2009 +0000
@@ -512,7 +512,7 @@ sub process_hubbub_notification {
 
     # needed for the future; get it early
     my $sclient = LJ::theschwartz() or die;
-    my $dbr = LJ::get_db_reader() or die;
+    my $dbh = LJ::get_db_writer() or die;
 
     # FIXME: this probably will explode horribly with aggregated content, so as
     # soon as that becomes supported somewhere, we need to fix this
@@ -540,19 +540,28 @@ sub process_hubbub_notification {
     # allow N feeds to have the same topic url and we schedule a refresh for 
all of them.
     # a little more work for us and potentially more traffic, but it's better 
than the
     # alternative...
-    my @uids;
+    my ( %uniqid, @rows );
     foreach my $topic ( @{ $feed->{self} } ) {
-        my $uids = $dbr->selectcol_arrayref(
-            'SELECT userid FROM syndicated_hubbub2 WHERE topicurl = ?',
+        my $rowrefs = $dbh->selectall_arrayref(
+            'SELECT id, userid FROM syndicated_hubbub2 WHERE topicurl = ?',
             undef, $topic
         );
-        die if $dbr->err;
+        die if $dbh->err;
 
-        push @uids, @{ $uids || [] };
+        foreach my $row ( @$rowrefs ) {
+            next if $uniqid{$row->[0]}++;
+            push @rows, $row;
+        }
     }
 
     # iterate over each user
-    foreach my $uid ( @uids ) {
+    foreach my $row ( @rows ) {
+        my ( $id, $uid ) = @$row;
+
+        # update the times pinged of this row
+        $dbh->do( 'UPDATE syndicated_hubbub2 SET timespinged = timespinged + 1 
WHERE id = ?',
+                  undef, $id );
+
         # user must still be visible for us to care
         my $u = LJ::load_userid( $uid ) or die;
         next unless $u->is_visible;
@@ -573,12 +582,4 @@ sub process_hubbub_notification {
 }
 
 
-
 1;
-
-
-# Local Variables:
-# mode: perl
-# c-basic-indent: 4
-# indent-tabs-mode: nil
-# End:
diff -r 7a377ed2f65e -r b8b7f42b8a41 htdocs/userinfo.bml
--- a/htdocs/userinfo.bml       Sat Oct 03 15:27:21 2009 +0000
+++ b/htdocs/userinfo.bml       Sun Oct 04 00:47:02 2009 +0000
@@ -462,6 +462,42 @@ body<=
             links           => $links,
         );
     }
+
+################################################################################
+##### PUBSUBHUBBUB INFORMATION FOR SYNDICATED ACCOUNTS
+
+    my $fredbody = '';
+
+    if ( $is_full && ( my @rows = $profile->hubbub_info_rows ) ) {
+        foreach my $row (@rows) {
+            my @data = (
+                id => $row->{id},
+                pings => $row->{timespinged},
+                huburl => LJ::ehtml( $row->{huburl} ),
+                topicurl => LJ::ehtml( $row->{topicurl} ),
+                lastseen => LJ::ago_text( $row->{lastseen} ),
+                goodfor => LJ::mysql_time( $row->{leasegoodto} ),
+            );
+
+            my @row_texts;
+            while ( @data && ( my ( $ml, $txt ) = splice( @data, 0, 2 ) ) ) {
+                push @row_texts, LJ::Lang::ml( '.label.syn.hubbub.' . $ml ) . 
'</th><td>' . $txt;
+            }
+
+            $fredbody .= q{ <div class="userinfo"><table><tr><th> };
+            $fredbody .= join( '</td></tr><tr><th>', @row_texts );
+            $fredbody .= q{ </td></tr></table></div> };
+        }
+    }
+
+    if ( $fredbody ) {
+        $ret .= $content_block->(
+            section_name    => 'hubbub',
+            section_name_ml => '.hubbub.header',
+            body            => $fredbody,
+        );
+    }
+
 
 
################################################################################
 ##### BIO
diff -r 7a377ed2f65e -r b8b7f42b8a41 htdocs/userinfo.bml.text
--- a/htdocs/userinfo.bml.text  Sat Oct 03 15:27:21 2009 +0000
+++ b/htdocs/userinfo.bml.text  Sun Oct 04 00:47:02 2009 +0000
@@ -148,6 +148,8 @@
 
 .flag=Flag Journal
 
+.hubbub.header=PubSubHubbub Status
+
 .im.aol=AIM
 
 .im.aol.status=AIM status
@@ -289,6 +291,18 @@
 .label.syndicatedstatus=Syndication Status:
 
 .label.syndreadcount=Number of Readers:
+
+.label.syn.hubbub.goodfor=Expiration time:
+
+.label.syn.hubbub.huburl=Hub URL:
+
+.label.syn.hubbub.id=Subscription id:
+
+.label.syn.hubbub.lastseen=Last seen at:
+
+.label.syn.hubbub.pings=Pings received:
+
+.label.syn.hubbub.topicurl=Topic URL:
 
 .label.textmessage=<nobr>Text<br>Message</nobr>:
 
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to