[pLog-svn] r2789 - in plog/trunk/class: dao view
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Sun Jan 15 20:19:24 GMT 2006
Author: oscar
Date: 2006-01-15 20:19:23 +0000 (Sun, 15 Jan 2006)
New Revision: 2789
Added:
plog/trunk/class/dao/recentarticles.class.php
Modified:
plog/trunk/class/dao/articles.class.php
plog/trunk/class/view/blogview.class.php
Log:
Added a class to take care of the caching of recent articles.
Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php 2006-01-15 15:45:09 UTC (rev 2788)
+++ plog/trunk/class/dao/articles.class.php 2006-01-15 20:19:23 UTC (rev 2789)
@@ -3,7 +3,6 @@
include_once( PLOG_CLASS_PATH.'class/dao/model.class.php' );
include_once( PLOG_CLASS_PATH.'class/dao/article.class.php' );
include_once( PLOG_CLASS_PATH.'class/dao/articlestatus.class.php' );
- include_once( PLOG_CLASS_PATH.'class/config/config.class.php' );
/**
* cache ids used by this class
@@ -278,15 +277,25 @@
{
$postStatus = $status;
$prefix = $this->getPrefix();
- $where = $this->buildWhere( $blogId, $date, $amount, $categoryId, $status, $userId, $maxDate, $searchTerms );
+ $where = $this->buildWhere( $blogId, $date, $amount, $categoryId, $status, $userId, $maxDate, $searchTerms );
$query = "SELECT COUNT(*) AS total FROM {$prefix}articles a, {$prefix}articles_categories c, {$prefix}article_categories_link l WHERE $where ";
$result = $this->_db->Execute( $query );
if( !$result )
return 0;
-
- $number = $result->RowCount();
+
+ /**
+ * :HACK:
+ * this really is a dirty hack...
+ */
+ if( $categoryId > 0 ) {
+ $row = $result->FetchRow();
+ $number = $row["total"];
+ }
+ else {
+ $number = $result->RowCount();
+ }
return( $number );
}
@@ -300,7 +309,7 @@
$status = POST_STATUS_PUBLISHED,
$userId = 0,
$maxDate = 0 )
- {
+ {
if( $status != POST_STATUS_ALL ) {
if( $article->getStatus() != $status )
return false;
@@ -783,6 +792,8 @@
}
// and finally clear the cache :)
+ include_once( PLOG_CLASS_PATH."class/dao/recentarticles.class.php" );
+ RecentArticles::resetRecentArticlesCache( $newArticle->getBlogId());
$this->_cache->removeData( $newArticle->getBlogId(), CACHE_ARTICLES_BYBLOG );
$this->_cache->removeData( $newArticle->getBlogId(), CACHE_ARTICLESPERMONTH );
@@ -867,6 +878,8 @@
'article_id',
$article->getId() );
+ include_once( PLOG_CLASS_PATH."class/dao/recentarticles.class.php" );
+ RecentArticles::resetRecentArticlesCache( $article->getBlogId());
$this->_cache->removeData( $article->getId(), CACHE_ARTICLETEXT );
return($this->Execute( $query ));
@@ -895,6 +908,8 @@
return false;*/
// clean up the cache
+ include_once( PLOG_CLASS_PATH."class/dao/recentarticles.class.php" );
+ RecentArticles::resetRecentArticlesCache( $article->getBlogId());
$this->_cache->removeData( $article->getBlogId(), CACHE_ARTICLESPERMONTH );
$this->_cache->removeData( $article->getId(), CACHE_ARTICLES );
$this->_cache->removeData( $article->getBlogId(), CACHE_ARTICLES_BYBLOG );
@@ -1036,7 +1051,9 @@
// -- custom fields --
$customFields = new CustomFieldsValues();
$customFields->removeArticleCustomFields( $artId );
-
+
+ include_once( PLOG_CLASS_PATH."class/dao/recentarticles.class.php" );
+ RecentArticles::resetRecentArticlesCache( $blogId );
$this->_cache->removeData( $blogId, CACHE_ARTICLES_BYBLOG );
$this->_cache->removeData( $blogId, CACHE_ARTICLESPERMONTH );
$this->_cache->removeData( $artId, CACHE_ARTICLES );
Added: plog/trunk/class/dao/recentarticles.class.php
===================================================================
--- plog/trunk/class/dao/recentarticles.class.php 2006-01-15 15:45:09 UTC (rev 2788)
+++ plog/trunk/class/dao/recentarticles.class.php 2006-01-15 20:19:23 UTC (rev 2789)
@@ -0,0 +1,58 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+
+ /**
+ * small wrapper to Articles that loads and caches recent articles. As an API user, you probably
+ * don't need to use this class unless you're implementing your own front-end to LifeType.
+ */
+
+ define( "CACHE_RECENT_ARTICLES_BY_BLOG", "recent_articles_by_blog" );
+
+ /**
+ * @see Articles
+ */
+ class RecentArticles extends Articles
+ {
+ /**
+ * @param blogId
+ * @param amount
+ * @return An array of Article objects
+ * @see Article
+ */
+ function getRecentArticles( $blogId, $amount )
+ {
+ // check if the data is there
+ $recentPosts = $this->_cache->getData( $blogId, CACHE_RECENT_ARTICLES_BY_BLOG );
+ if( !$recentPosts ) {
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+ $t = new Timestamp();
+ $todayTimestamp = $t->getTimestamp();
+
+ // load the data if not available
+ $recentPosts = $this->getBlogArticles( $blogId,
+ -1,
+ $amount,
+ 0,
+ 1,
+ 0,
+ $todayTimestamp);
+
+ // and cache it for future use
+ $this->_cache->setData( $blogId, CACHE_RECENT_ARTICLES_BY_BLOG, $recentPosts );
+ }
+
+ return( $recentPosts );
+ }
+
+ /**
+ * Called whenever the cache needs to be cleaned up.
+ * @static
+ */
+ function resetRecentArticlesCache( $blogId )
+ {
+ $cache =& CacheManager::getCache();
+ $cache->removeData( $blogId, CACHE_RECENT_ARTICLES_BY_BLOG );
+ }
+ }
+?>
\ No newline at end of file
Modified: plog/trunk/class/view/blogview.class.php
===================================================================
--- plog/trunk/class/view/blogview.class.php 2006-01-15 15:45:09 UTC (rev 2788)
+++ plog/trunk/class/view/blogview.class.php 2006-01-15 20:19:23 UTC (rev 2789)
@@ -120,15 +120,12 @@
*/
function _getRecentPosts()
{
- include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
+ include_once( PLOG_CLASS_PATH.'class/dao/recentarticles.class.php' );
$blogSettings = $this->_blogInfo->getSettings();
-
- $t = new Timestamp();
- $todayTimestamp = $t->getTimestamp();
-
- $recentPosts = $this->articles->getBlogArticles( $this->_blogInfo->getId(), -1, $blogSettings->getValue( 'recent_posts_max' ), 0, 1, 0, $todayTimestamp);
-
+ $recent = new RecentArticles();
+ $recentPosts = $recent->getRecentArticles( $this->_blogInfo->getId(),
+ $blogSettings->getValue( 'recent_posts_max' ));
$this->_pm->notifyEvent( EVENT_POSTS_LOADED, Array( 'articles' => &$recentPosts ));
return $recentPosts;
More information about the pLog-svn
mailing list