mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-11-04 08:33 am

[dw-free] Implement Latest Posts feed

[commit: http://hg.dwscoalition.org/dw-free/rev/9c974535771b]

http://bugs.dwscoalition.org/show_bug.cgi?id=316

Implement [personal profile] exor674's suggestion to make tag based feeds support
groups of tags.

Patch by [staff profile] mark.

Files modified:
  • cgi-bin/DW/LatestFeed.pm
  • doc/config-private.pl.txt
  • htdocs/latest.bml
--------------------------------------------------------------------------------
diff -r bc5ceaf8b7c4 -r 9c974535771b cgi-bin/DW/LatestFeed.pm
--- a/cgi-bin/DW/LatestFeed.pm	Mon Nov 02 22:36:37 2009 -0600
+++ b/cgi-bin/DW/LatestFeed.pm	Wed Nov 04 08:33:07 2009 +0000
@@ -65,7 +65,7 @@ sub new_item {
 # returns arrayref of item hashrefs that you can handle and display if you want
 sub get_items {
     my ( $class, %opts ) = @_;
-    return if $opts{tag} && ! exists $LJ::LATEST_TAGS{$opts{tag}};
+    return if $opts{feed} && ! exists $LJ::LATEST_TAG_FEEDS{group_names}->{$opts{feed}};
 
     # make sure we process the queue of items first.  this makes sure that if we
     # don't have much traffic we don't have to wait for new posts to drive the
@@ -73,8 +73,8 @@ sub get_items {
     $class->_process_queue;
 
     # and simply get the list and return it ... simplicity
-    my $mckey = $opts{tag} ? "latest_items_tag:$opts{tag}" : "latest_items";
-    return LJ::MemCache::get( $mckey );
+    my $mckey = $opts{feed} ? "latest_items_tag:$opts{feed}" : "latest_items";
+    return LJ::MemCache::get( $mckey ) || [];
 }
 
 # INTERNAL; called by the worker when there's an item for us to handle.  at this
@@ -116,7 +116,7 @@ sub _process_item {
 }
 
 
-# INTERNL; called and attempts to do something with the latest items queue 
+# INTERNAL; called and attempts to do something with the latest items queue
 sub _process_queue {
     my ( $class, %opts ) = @_;
 
@@ -247,8 +247,11 @@ sub _process_queue {
 
         # step 7.5) if the entry contains any tags that we are currently showing
         # globally, then put that onto the list
-        foreach my $tag ( grep { $LJ::LATEST_TAGS{$_} } $ent->tags ) {
-            my $nom = "latest_items_tag:$tag";
+        foreach my $tag ( $ent->tags ) {
+            my $feed = $LJ::LATEST_TAG_FEEDS{tag_maps}->{$tag};
+            next unless $feed;
+
+            my $nom = "latest_items_tag:$feed";
             $lists{$nom} ||= LJ::MemCache::get( $nom ) || [];
             unshift @{$lists{$nom}}, $item;
         }
diff -r bc5ceaf8b7c4 -r 9c974535771b doc/config-private.pl.txt
--- a/doc/config-private.pl.txt	Mon Nov 02 22:36:37 2009 -0600
+++ b/doc/config-private.pl.txt	Wed Nov 04 08:33:07 2009 +0000
@@ -104,8 +104,20 @@
     # your own (or use any other hub you want).
     # @HUBBUB_HUBS = ( 'http://pubsubhubbub.appspot.com/' );
 
-    # Add any tags here that you wish to create global 'latest posts' feeds for
-    # %LATEST_TAGS = ( map { $_ => 1 } qw/ tag othertag bigtag littletag / );
+    # Add any tags here that you wish to create global 'latest posts' feed groups.
+    # %LATEST_TAG_FEEDSS =
+    #     group_names => {
+    #         # short name => long name, used for the UI
+    #         nnwm09 => 'NaNoWriMo 2009',
+    #     },
+    #
+    #     tag_maps => {
+    #         # tag => short name, in this case, all of the tags in the list on the
+    #         # right map to the 'nnwm09' group on the left
+    #         map { $_ => 'nnwm09' } ( 'nnwm09', 'nano', 'nanowrimo' ),
+    #     },
+    # );
+
 }
 
 {
diff -r bc5ceaf8b7c4 -r 9c974535771b htdocs/latest.bml
--- a/htdocs/latest.bml	Mon Nov 02 22:36:37 2009 -0600
+++ b/htdocs/latest.bml	Wed Nov 04 08:33:07 2009 +0000
@@ -22,11 +22,11 @@ body<=
 
     LJ::need_res( 'stc/latest.css' );
 
-    my ( $type, $max, $fmt, $tag ) = ( $GET{type}, ($GET{max}+0)||100, $GET{fmt}, $GET{tag} );
+    my ( $type, $max, $fmt, $feed ) = ( $GET{type}, ($GET{max}+0)||100, $GET{fmt}, $GET{feed}||$GET{tag} );
     $type = { entries => 'entry', comments => 'comment' }->{$type}  || 'entry';
     $max = 100 if $max > 1000;
     $fmt = { rss => 'rss', atom => 'atom', html => 'html' }->{$fmt} || 'html';
-    $tag = '' unless $tag && exists $LJ::LATEST_TAGS{$tag};
+    $feed = '' unless $feed && exists $LJ::LATEST_TAG_FEEDS{tag_maps}->{$feed};
 
     # if they want a format we don't support ... FIXME: implement all formats
     return "Sorry, that format is not supported yet."
@@ -34,7 +34,7 @@ body<=
 
     # see if somebody has asked for this particular feed in the last minute or so, in
     # which case it is going to be in memcache
-    my $mckey = "latest_src:$type:$max:$fmt" . ( $tag ? ":$tag" : '' );
+    my $mckey = "latest_src:$type:$max:$fmt" . ( $feed ? ":$feed" : '' );
     my $page = LJ::MemCache::get( $mckey );
 
     # return from the cache
@@ -60,7 +60,7 @@ body<=
     }
 
     # ask for the items from the latest feed
-    my $items = DW::LatestFeed->get_items( tag => $tag );
+    my $items = DW::LatestFeed->get_items( feed => $feed );
     return "Failed to get latest items."
         unless $items && ref $items eq 'ARRAY';
 
@@ -94,13 +94,14 @@ body<=
     }
 
     # output the header data
-    my $tagfeeds = join ' ', map { $tag eq $_ ? $_ : qq{<a href="$LJ::SITEROOT/latest?tag=$_">$_</a>} } 
-                             sort { $a cmp $b } keys %LJ::LATEST_TAGS;
-    if ( $tag ) {
+    my $tagfeeds = join ' ', map { $feed eq $_ ? $LJ::LATEST_TAG_FEEDS{group_names}->{$_}
+                                               : qq(<a href="$LJ::SITEROOT/latest?feed=$_">$LJ::LATEST_TAG_FEEDS{group_names}->{$_}</a>) } 
+                             sort { $a cmp $b } keys %{$LJ::LATEST_TAG_FEEDS{group_names}};
+    if ( $feed ) {
         $tagfeeds = qq{[<a href="$LJ::SITEROOT/latest">show all</a>] } . $tagfeeds;
     }
     if ( $tagfeeds ) {
-        $tagfeeds = qq{<?p Tag feeds are available for some well known tags: $tagfeeds p?>};
+        $tagfeeds = qq{<?p Filter posts by subject: $tagfeeds p?>};
     }
 
     my $ret = <<EOF;
--------------------------------------------------------------------------------
janinedog: (Default)

[personal profile] janinedog 2009-11-04 03:54 pm (UTC)(link)
Doesn't affect us, but you misspelled the hash name in the example config:

+ # %LATEST_TAG_FEEDSS =
gchick: Small furry animal wearing a tin-foil hat (Default)

[personal profile] gchick 2009-11-04 05:20 pm (UTC)(link)
\o/