[pLog-svn] r1733 - plog/branches/plog-1.1-ben/class/dao
ork at devel.plogworld.net
ork at devel.plogworld.net
Tue Apr 5 12:45:19 GMT 2005
Author: ork
Date: 2005-04-05 12:45:19 +0000 (Tue, 05 Apr 2005)
New Revision: 1733
Modified:
plog/branches/plog-1.1-ben/class/dao/blogs.class.php
Log:
added the cache .. and prettified some sql statements ..
Modified: plog/branches/plog-1.1-ben/class/dao/blogs.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/blogs.class.php 2005-04-05 12:14:57 UTC (rev 1732)
+++ plog/branches/plog-1.1-ben/class/dao/blogs.class.php 2005-04-05 12:45:19 UTC (rev 1733)
@@ -20,13 +20,19 @@
* @param extendedInfo
* @return Returns a BlogInfo object containing information about the blog
*/
- function getBlogInfo( $blogId, $extendedInfo = false )
+ function getBlogInfo( $blogId )
{
- $query = "SELECT * FROM ".$this->getPrefix()."blogs WHERE id = '".Db::qstr($blogId)."'";
+ require_once( PLOG_CLASS_PATH . "class/dao/blogsettings.class.php" );
- $blogInfo = $this->_getBlogInfoFromQuery( $query, $extendedInfo );
-
- return $blogInfo;
+ $blogInfo = $this->_cache->getData( $blogId, CACHE_BLOGINFOS );
+
+ if( !$blogInfo ) {
+ $query = "SELECT * FROM ".$this->getPrefix()."blogs " .
+ "WHERE id = '".Db::qstr($blogId)."'";
+ $blogInfo = $this->_getBlogInfoFromQuery( $query, $extendedInfo );
+ }
+
+ return $blogInfo;
}
/**
@@ -37,11 +43,19 @@
*/
function getBlogInfoByName( $blogName, $extendedInfo = false )
{
- $query = "SELECT * FROM ".$this->getPrefix()."blogs WHERE mangled_blog = '".Db::qstr($blogName)."';";
+ require_once( PLOG_CLASS_PATH . "class/dao/blogsettings.class.php" );
- //$this->_db->debug=true;
+ $blogInfo = $this->_cache->getData( $blogName, CACHE_BLOGIDBYNAME );
- return $this->_getBlogInfoFromQuery( $query, $extendedInfo );
+ if ( !$blogId ) {
+ $query = "SELECT * FROM " . $this->getPrefix() . "blogs " .
+ "WHERE mangled_blog = '" . Db::qstr($blogName) . "';";
+
+ $blogInfo = $this->_getBlogInfoFromQuery( $query, $extendedInfo );
+ $this->_cache->setData( $blogName, CACHE_BLOGIDBYNAME, $blogInfo->getId() );
+ }
+
+ return $blogInfo;
}
/**
@@ -72,10 +86,10 @@
*/
function _fillBlogInformation( $query_result, $extended = false )
{
- // source class
+ // source class
include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
- // create new BlogInfo
+ // create new BlogInfo
$blogInfo = new BlogInfo( stripslashes($query_result["blog"]),
$query_result["owner_id"],
stripslashes($query_result["about"]),
@@ -96,7 +110,8 @@
*/
function getBlogCreateDate( $blogId )
{
- $query = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date ASC LIMIT 0,1" ;
+ $query = "SELECT date FROM " . $this->getPrefix() . "articles " .
+ "WHERE blog_id = " . $blogId . " ORDER BY date ASC LIMIT 0,1";
$result = $this->Execute( $query );
@@ -119,7 +134,8 @@
*/
function getBlogUpdateDate( $blogId )
{
- $query = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date DESC LIMIT 0,1" ;
+ $query = "SELECT date FROM " . $this->getPrefix() . "articles " .
+ "WHERE blog_id = " . $blogId . " ORDER BY date DESC LIMIT 0,1";
$result = $this->Execute( $query );
if (!$result)
@@ -141,7 +157,8 @@
*/
function getBlogViewedTotal( $blogId )
{
- $query = "SELECT SUM(num_reads) as total FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId;
+ $query = "SELECT SUM(num_reads) as total FROM " . $this->getPrefix() .
+ "articles WHERE blog_id = " . $blogId;
$result = $this->Execute( $query );
@@ -276,36 +293,44 @@
// source classes
include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
- // include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
- $query = "UPDATE ".$this->getPrefix()."blogs SET
- blog = '".Db::qstr($blogInfo->getBlog()).
- "', about = '".Db::qstr($blogInfo->getAbout()).
- "', settings = '".serialize($blogInfo->getSettings()).
- "', owner_id = ".$blogInfo->getOwner().
- ", mangled_blog = '".TextFilter::urlize($blogInfo->getBlog()).
- "', status = '".Db::qstr($blogInfo->getStatus()).
- "' WHERE id = '".Db::qstr($blogId)."';";
+ $blogName = TextFilter::urlize($blogInfo->getBlog());
+ $query = "UPDATE ".$this->getPrefix()."blogs SET " .
+ "blog = '" . Db::qstr($blogInfo->getBlog()).
+ "', about = '" . Db::qstr($blogInfo->getAbout()).
+ "', settings = '" . serialize($blogInfo->getSettings()).
+ "', owner_id = " . $blogInfo->getOwner().
+ ", mangled_blog = '" . $blogName.
+ "', status = '" . Db::qstr($blogInfo->getStatus()).
+ "' WHERE id = '" . Db::qstr($blogId)."';";
+
$result = $this->Execute( $query );
+ $this->_cache->removeData( $blogName, CACHE_BLOGIDBYNAME );
+ $this->_cache->removeData( $blogId, CACHE_BLOGINFOS );
+
return $result;
}
- /**
- * Updates the settings of a blog
- *
- * @param blogId The blog we want to update
- * @param blogSettings the BlogSettings object that we would like to update
- * @return 'true' if all correct. 'false' otherwise.
- */
- function updateBlogSettings( $blogId, $blogSettings )
- {
- $query = "UPDATE ".$this->getPrefix()."blogs SET settings = '".serialize($blogSettings)."' WHERE id = ".$blogId;
+ /**
+ * Updates the settings of a blog
+ *
+ * @param blogId The blog we want to update
+ * @param blogSettings the BlogSettings object that we would like to update
+ * @return 'true' if all correct. 'false' otherwise.
+ */
+ function updateBlogSettings( $blogId, $blogSettings )
+ {
+ $query = "UPDATE ".$this->getPrefix()."blogs " .
+ "SET settings = '".serialize($blogSettings) .
+ "' WHERE id = ".$blogId;
$result = $this->Execute( $query );
+ $this->_cache->removeData( $blogId, CACHE_BLOGINFOS );
+
return $result;
- }
+ }
/**
* Sends a weblogsUpdate.ping xmlrpc call to notifiy of changes in this blog
@@ -519,6 +544,8 @@
if( $this->_db->Affected_Rows() == 0 )
return false;
+ $this->_cache->removeData( $blogId, CACHE_BLOGINFOS );
+
return true;
}
}
More information about the pLog-svn
mailing list