[Slashdotjp-dev 1220] [748] Add feature to store/get journal RSS content from memcached

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 9月 16日 (火) 23:36:01 JST


Revision: 748
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=slashdotjp&view=rev&rev=748
Author:   tach
Date:     2008-09-16 23:36:00 +0900 (Tue, 16 Sep 2008)

Log Message:
-----------
Add feature to store/get journal RSS content from memcached

Modified Paths:
--------------
    slashjp/branches/2.5.0.192/debian/changelog
    slashjp/branches/2.5.0.192/plugins/Journal/journal.pl


-------------- next part --------------
Modified: slashjp/branches/2.5.0.192/debian/changelog
===================================================================
--- slashjp/branches/2.5.0.192/debian/changelog	2008-09-16 13:47:56 UTC (rev 747)
+++ slashjp/branches/2.5.0.192/debian/changelog	2008-09-16 14:36:00 UTC (rev 748)
@@ -14,8 +14,9 @@
   * Add feature to change redirect status code on redirect()
   * Redirect to new journal RSS URL
   * Add feature storing RSS output into memcached
+  * Add feature to store/get journal RSS content from memcached
 
- -- Taku YASUI <tach****@osdn*****>  Tue, 16 Sep 2008 13:46:13 +0000
+ -- Taku YASUI <tach****@osdn*****>  Tue, 16 Sep 2008 14:35:19 +0000
 
 slash (2.5.0.192-16) unstable; urgency=low
 

Modified: slashjp/branches/2.5.0.192/plugins/Journal/journal.pl
===================================================================
--- slashjp/branches/2.5.0.192/plugins/Journal/journal.pl	2008-09-16 13:47:56 UTC (rev 747)
+++ slashjp/branches/2.5.0.192/plugins/Journal/journal.pl	2008-09-16 14:36:00 UTC (rev 748)
@@ -230,7 +230,13 @@
 		$juser  = $journal_reader->getUser($uid);
 	}
 	$juser ||= $user;
+	my $mcdkey = undef;
 
+	if ($form->{op} ne 'friendview') {
+		$mcdkey = "journal:display:$juser->{uid}";
+		_mcd_get($journal, $mcdkey) && return 1;
+	}
+
 	if ($form->{op} && $form->{op} eq 'friendview') {
 		my $zoo   = getObject('Slash::Zoo');
 		my $uids  = $zoo->getFriendsUIDs($juser->{uid});
@@ -306,7 +312,7 @@
 		items	=> \@items,
 		rdfitemdesc		=> $constants->{journal_rdfitemdesc},
 		rdfitemdesc_html	=> $rss_html,
-	});
+	}, { mcdkey => $mcdkey });
 }
 
 sub displayTopRSS {
@@ -314,14 +320,21 @@
 
 	my $journals;
 	my $type = '';
+	my $mcdkey = undef;
 	if ($form->{type} && $form->{type} eq 'count' && $constants->{journal_top_posters}) {
 		$type = 'count';
+		$mcdkey = "journal:top_count";
+		_mcd_get($journal, $mcdkey) && return 1;
 		$journals = $journal_reader->top;
 	} elsif ($form->{type} && $form->{type} eq 'friends' && $constants->{journal_top_friend}) {
 		$type = 'friends';
 		my $zoo   = getObject('Slash::Zoo');
+		$mcdkey = "journal:top_friend";
+		_mcd_get($journal, $mcdkey) && return 1;
 		$journals = $zoo->topFriends;
 	} elsif ($constants->{journal_top_recent}) {
+		$mcdkey = "journal:top_recent";
+		_mcd_get($journal, $mcdkey) && return 1;
 		$journals = $journal_reader->topRecent;
 	}
 
@@ -367,7 +380,7 @@
 		image	=> 1,
 		items	=> \@items,
 		rdfitemdesc		=> $constants->{journal_rdfitemdesc},
-	});
+	}, { mcdkey => $mcdkey });
 }
 
 sub displayArticleFriends {
@@ -755,6 +768,7 @@
 		}) if $validator;
 	}
 
+	_mcd_delete($journal, $user->{uid});
 	return 0;
 }
 
@@ -969,6 +983,7 @@
 			$journal->remove($id);
 		}
 	}
+	_mcd_delete($journal, $user->{uid});
 
 	listArticle(@_);
 }
@@ -1019,6 +1034,34 @@
 	return $theme;
 }
 
+sub _mcd_get {
+	my ($journal, $mcdkey) = @_;
+	my $mcd = $journal->getMCD();
+	if ($mcd) {
+		my $data = $mcd->get("$journal->{_mcd_keyprefix}:xmldcache:rss:$mcdkey");
+		if ($data->{content}) {
+			http_send({
+				content_type	=> 'application/rss+xml',
+				etag		=> ($data->{etag} || undef),
+				content		=> $data->{content},
+			});
+			return 1;
+		}
+	}
+	return 0;
+}
+
+sub _mcd_delete {
+	my ($journal, $uid) = @_;
+	my $mcd = $journal->getMCD();
+	if ($mcd) {
+		$mcd->delete("$journal->{_mcd_keyprefix}:xmldcache:rss:journal:display:$uid", 1);
+		$mcd->delete("$journal->{_mcd_keyprefix}:xmldcache:rss:journal:top_count", 1);
+		$mcd->delete("$journal->{_mcd_keyprefix}:xmldcache:rss:journal:top_recent", 1);
+		$mcd->delete("$journal->{_mcd_keyprefix}:xmldcache:rss:journal:top_friend", 1);
+	}
+}
+
 createEnvironment();
 main();
 


Slashdotjp-dev メーリングリストの案内
Back to archive index