[pLog-svn] r1863 - in plog/branches/plog-1.1-ben/class: cache dao
view/admin
ork at devel.plogworld.net
ork at devel.plogworld.net
Sun Apr 17 21:25:17 GMT 2005
Author: ork
Date: 2005-04-17 21:25:16 +0000 (Sun, 17 Apr 2005)
New Revision: 1863
Modified:
plog/branches/plog-1.1-ben/class/cache/cache.class.php
plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php
plog/branches/plog-1.1-ben/class/dao/trackbacks.class.php
plog/branches/plog-1.1-ben/class/view/admin/adminarticletrackbackslistview.class.php
Log:
enabled caching of trackbacks ..
Modified: plog/branches/plog-1.1-ben/class/cache/cache.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/cache/cache.class.php 2005-04-17 20:51:02 UTC (rev 1862)
+++ plog/branches/plog-1.1-ben/class/cache/cache.class.php 2005-04-17 21:25:16 UTC (rev 1863)
@@ -2,7 +2,6 @@
require_once( PLOG_CLASS_PATH . "class/object/object.class.php" );
require_once( PLOG_CLASS_PATH . "class/cache/Cache_Lite/Lite.php" );
- require_once( PLOG_CLASS_PATH . "class/logger/loggermanager.class.php" );
/**
* Provides a singleton for storing and retrieving data from a global cache.
@@ -20,8 +19,8 @@
function setData( $id, $group, $data )
{
- return $this->cache->save( $data, $id, $group );
$this->log->info("Caching $id ($group):" . $data );
+ return $this->cache->save( $data, $id, $group );
}
function getData( $id, $group )
Modified: plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php 2005-04-17 20:51:02 UTC (rev 1862)
+++ plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php 2005-04-17 21:25:16 UTC (rev 1863)
@@ -10,6 +10,8 @@
define( "CACHE_BLOGINFOS", "bloginfo" );
define( "CACHE_BLOGIDBYNAME", "bloginfo_idbyname" );
define( "CACHE_ARTICLETEXT", "article_text" );
+ define( "CACHE_TRACKBACKS", "trackbacks" );
+ define( "CACHE_NUMTRACKBACKS", "trackbacks_size" );
define( "CACHE_CONFIGDBSTORAGE", "config_db_storage" );
/**
Modified: plog/branches/plog-1.1-ben/class/dao/trackbacks.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/trackbacks.class.php 2005-04-17 20:51:02 UTC (rev 1862)
+++ plog/branches/plog-1.1-ben/class/dao/trackbacks.class.php 2005-04-17 21:25:16 UTC (rev 1863)
@@ -3,6 +3,8 @@
include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/trackback.class.php" );
+ define( 'NO_TRACKBACKS', 'no trackbacks available' );
+
/**
* Implementation of a trackback feature.
* The technical specifications of the trackback protocol can be found
@@ -62,6 +64,10 @@
// set the trackback id
$trackback->setId( $this->_db->Insert_ID());
+
+ // clear the cache
+ $this->_cache->removeData( $artId, CACHE_TRACKBACKS );
+ $this->_cache->removeData( $artId, CACHE_NUMTRACKBACKS );
return true;
}
@@ -74,48 +80,61 @@
* @param itemsPerPage
* @return An array of TrackbackItem objects with the information, or false otherwise.
*/
- function getArticleTrackBacks( $artId, $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+ function getArticleTrackbacks( $artId, $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
{
- $query = "SELECT * FROM ".$this->getPrefix()."trackbacks WHERE article_id = '".Db::qstr($artId)."'";
+ $trackbacks = $this->_cache->getData( $artId, CACHE_TRACKBACKS );
- $result = $this->Execute( $query, $page, $itemsPerPage );
+ if ( !$trackbacks ) {
+ $query = "SELECT * FROM ".$this->getPrefix()."trackbacks WHERE article_id = '".Db::qstr($artId)."'";
- if( !$result )
- return false;
+ $result = $this->Execute( $query, $page, $itemsPerPage );
- $trackbacks = Array();
- while( $row = $result->FetchRow()) {
- //$trackback = $this->_fillTrackbackInformation( $row );
-
- // find out the blogInfo object (after all, all these comments belong to the same
- // blog so there is no risk of finding different blog_ids anywhere!
- if( $this->blogSettings == null ) {
- $prefix = $this->getPrefix();
- $articleId = $row["article_id"];
-
- $query = "SELECT DISTINCT b.settings AS settings FROM {$prefix}blogs b, {$prefix}articles a,
- {$prefix}articles_comments c WHERE c.article_id = a.id AND a.blog_id = b.id
- AND a.id = $articleId";
- $result2 = $this->Execute( $query );
- $tmpRow = $result2->FetchRow();
- $this->blogSettings = Blogs::getBlogSettingsFromField( $tmpRow["settings"] );
- $this->timeDiff = $this->blogSettings->getValue( "time_offset" );
- }
-
- // now that we've got the time difference, we can
- // calculate what would the "real" date...
- $date = $row["date"];
- $date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
+ if( !$result )
+ return false;
- $trackback = new TrackBack( $row["url"],
- $row["title"],
- $row["article_id"],
- $row["excerpt"],
- $row["blog_name"],
- $date,
- $row["id"] );
-
- $trackbacks[] = $trackback;
+ $trackbacks = Array();
+ while( $row = $result->FetchRow()) {
+ //$trackback = $this->_fillTrackbackInformation( $row );
+
+ // find out the blogInfo object (after all, all these comments belong to the same
+ // blog so there is no risk of finding different blog_ids anywhere!
+ if( $this->blogSettings == null ) {
+ $prefix = $this->getPrefix();
+ $articleId = $row["article_id"];
+
+ $query = "SELECT DISTINCT b.settings AS settings FROM {$prefix}blogs b, {$prefix}articles a,
+ {$prefix}articles_comments c WHERE c.article_id = a.id AND a.blog_id = b.id
+ AND a.id = $articleId";
+ $result2 = $this->Execute( $query );
+ $tmpRow = $result2->FetchRow();
+ $this->blogSettings = Blogs::getBlogSettingsFromField( $tmpRow["settings"] );
+ $this->timeDiff = $this->blogSettings->getValue( "time_offset" );
+ }
+
+ // now that we've got the time difference, we can
+ // calculate what would the "real" date...
+ $date = $row["date"];
+ $date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
+
+ $trackback = new TrackBack( $row["url"],
+ $row["title"],
+ $row["article_id"],
+ $row["excerpt"],
+ $row["blog_name"],
+ $date,
+ $row["id"] );
+
+ $trackbacks[] = $trackback;
+
+ }
+ // fill the cache
+ if ( $trackbacks == array() ) {
+ $this->_cache->setData( $artId, CACHE_TRACKBACKS, NO_TRACKBACKS );
+ } else {
+ $this->_cache->setData( $artId, CACHE_TRACKBACKS, $trackbacks );
+ }
+ } elseif ($trackbacks == NO_TRACKBACKS ) {
+ return array();
}
return $trackbacks;
@@ -157,67 +176,6 @@
return( $trackbacks );
}
- /**
- * returns a list of trackbacks given an array with article ids
- *
- * @param artIds An array of article ids
- * @return An array of Trackback objects
- * @see getArticleTrackback
- */
- function getArticleTrackBacksByIds( $artIds )
- {
- $trackbacks = array();
-
- $query = "SELECT * FROM ".$this->getPrefix()."trackbacks WHERE article_id IN (".$artIds.")";
-
- $result = $this->Execute( $query );
-
- if( !$result )
- return Array();
-
- // harmless values, but they mark that we haven't loaded any data yet!
- $blogSettings = null;
- $timeDiff = 0;
-
- while ($row = $result->FetchRow()) {
-
- // find out the blogInfo object (after all, all these comments belong to the same
- // blog so there is no risk of finding different blog_ids anywhere!
- if( $this->blogSettings == null ) {
- $prefix = $this->getPrefix();
- $articleId = $row["article_id"];
-
- $query = "SELECT DISTINCT b.settings AS settings FROM {$prefix}blogs b, {$prefix}articles a,
- {$prefix}articles_comments c WHERE c.article_id = a.id AND a.blog_id = b.id
- AND a.id = $articleId";
- $result2 = $this->Execute( $query );
- $tmpRow = $result2->FetchRow();
- $this->blogSettings = Blogs::getBlogSettingsFromField( $tmpRow["settings"] );
-
- $this->timeDiff = $this->blogSettings->getValue( "time_offset" );
- }
-
- $lastArticleId=$row["article_id"];
-
- // now that we've got the time difference, we can
- // calculate what would the "real" date...
- $date = $row["date"];
- $date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
-
- $trackback = new TrackBack( $row["url"],
- $row["title"],
- $row["article_id"],
- $row["excerpt"],
- $row["blog_name"],
- $date,
- $row["id"] );
-
- $trackbacks[$lastArticleId][]=$trackback;
- }
-
- return $trackbacks;
- }
-
/**
* function factored out from the above
*
@@ -274,15 +232,22 @@
*/
function getNumTrackbacksArticle( $artId )
{
- if( empty($this->totalTrackbacks)) {
- $query1 = "SELECT article_id, COUNT(*) AS 'count' FROM ".$this->getPrefix()."trackbacks GROUP BY (article_id)";
- $this->totalTrackbacks = $this->_db->GetAssoc( $query1 );
+ $totalTrackbacks = $this->_cache->getData( $artId, CACHE_NUMTRACKBACKS );
+
+ if ( !$totalTrackbacks ) {
+ if( empty($this->totalTrackbacks) ) {
+ $query1 = "SELECT article_id, COUNT(*) AS 'count' FROM ".$this->getPrefix()."trackbacks GROUP BY (article_id)";
+ $this->_initializeDb();
+ $this->totalTrackbacks = $this->_db->GetAssoc( $query1 );
+ }
+
+ $totalTrackbacks = $this->totalTrackbacks[$artId];
+ if( $totalTrackbacks == "" ) $totalTrackbacks = 0;
+ $this->_cache->setData( $artId, CACHE_NUMTRACKBACKS, $totalTrackbacks );
}
- $totalTrackbacks = $this->totalTrackbacks[$artId];
- if( $totalTrackbacks == "" ) $totalTrackbacks = 0;
-
return $totalTrackbacks;
+
}
/**
@@ -296,11 +261,16 @@
$result = $this->Execute( $query );
+ // clear the cache
+ $this->_cache->removeData( $artId, CACHE_TRACKBACKS );
+ $this->_cache->removeData( $artId, CACHE_NUMTRACKBACKS );
+
return $result;
}
/**
* gets a single trackback from the db
+ * only used by the admin panel, no caching enabled
*
* @param trackbackId
* @param postId
@@ -333,7 +303,7 @@
* @param articleId
* @return True if successful or false otherwise
*/
- function deletePostTrackback( $trackbackId, $articleId = -1 )
+ function deletePostTrackback( $trackbackId, $articleId )
{
$prefix = $this->getPrefix();
$query = "DELETE FROM {$prefix}trackbacks WHERE id = '".Db::qstr($trackbackId)."'";
@@ -341,6 +311,10 @@
$query .= " AND article_id = '".Db::qstr($articleId)."'";
return $this->Execute( $query );
+
+ // clear the cache
+ $this->_cache->removeData( $artId, CACHE_TRACKBACKS );
+ $this->_cache->removeData( $artId, CACHE_NUMTRACKBACKS );
}
}
?>
Modified: plog/branches/plog-1.1-ben/class/view/admin/adminarticletrackbackslistview.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/view/admin/adminarticletrackbackslistview.class.php 2005-04-17 20:51:02 UTC (rev 1862)
+++ plog/branches/plog-1.1-ben/class/view/admin/adminarticletrackbackslistview.class.php 2005-04-17 21:25:16 UTC (rev 1863)
@@ -38,7 +38,7 @@
$this->notifyEvent( EVENT_TRACKBACKS_LOADED, Array( "trackbacks" => &$postTrackbacks ));
$this->setValue( "trackbacks", $postTrackbacks);
// and the total number of trackbacks
- $numTrackbacks = $trackbacks->getNumTrackbacksArticle( $this->_article->getId());
+ $numTrackbacks = count( $postTrackbacks );
// create and export the pager to the view
$pager = new Pager( "?op=editTrackbacks&articleId=".$this->_article->getId()."&page=",
@@ -52,4 +52,4 @@
parent::render();
}
}
-?>
\ No newline at end of file
+?>
More information about the pLog-svn
mailing list