[pLog-svn] r1221 - in plog/trunk/class: dao summary/dao
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Sat Feb 26 22:58:45 GMT 2005
Author: oscar
Date: 2005-02-26 22:58:45 +0000 (Sat, 26 Feb 2005)
New Revision: 1221
Modified:
plog/trunk/class/dao/bloginfo.class.php
plog/trunk/class/dao/blogs.class.php
plog/trunk/class/summary/dao/summarystats.class.php
Log:
some more performance improvements... they have sped up the summary page quite a bit
Modified: plog/trunk/class/dao/bloginfo.class.php
===================================================================
--- plog/trunk/class/dao/bloginfo.class.php 2005-02-26 22:26:32 UTC (rev 1220)
+++ plog/trunk/class/dao/bloginfo.class.php 2005-02-26 22:58:45 UTC (rev 1221)
@@ -8,6 +8,8 @@
include_once( PLOG_CLASS_PATH."class/dao/blogsettings.class.php" );
include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
/**
* This is the representation of a blog. It contains all the information we need to know,
@@ -66,6 +68,12 @@
// default status is active
$this->_status = BLOG_STATUS_ACTIVE;
+
+ // values that are loaded on demand
+ $this->_updateTimestamp = null;
+ $this->_viewedTotal = null;
+ $this->_totalPosts = null;
+ $this->_createTimestamp = null;
}
/**
@@ -163,6 +171,12 @@
*/
function getCreateDateObject( )
{
+ // if it hasn't been loaded yet...
+ if( $this->_createTimestamp == null ) {
+ $blogs = new Blogs();
+ $this->_createTimestamp = $blogs->getBlogCreateDate( $this->getId());
+ }
+
return $this->_createTimestamp;
}
@@ -170,6 +184,11 @@
*/
function getUpdateDateObject( )
{
+ if( $this->_updateTimestamp == null ) {
+ $blogs = new Blogs();
+ $this->_updateTimestamp = $blogs->getBlogUpdateDate( $this->getId());
+ }
+
return $this->_updateTimestamp;
}
@@ -177,6 +196,11 @@
*/
function getTotalPosts( )
{
+ if( $this->_totalPosts == null ) {
+ $blogs = new Blogs();
+ $this->_totalPosts = $blogs->getBlogTotalPosts( $this->getId());
+ }
+
return $this->_totalPosts;
}
@@ -184,6 +208,11 @@
*/
function getViewedTotal( )
{
+ if( $this->_viewedTotal == null ) {
+ $blogs = new Blogs();
+ $this->_viewedTotal = $blogs->getBlogViewedTotal( $this->getId());
+ }
+
return $this->_viewedTotal;
}
@@ -199,6 +228,12 @@
*/
function getUsersInfo( )
{
+ if( $this->_usersInfo == null ) {
+ $userpermissions = new UserPermissions();
+ $blogUsers = $userpermissions->getBlogUsers( $blogInfo->getId());
+ $blogInfo->setUsersInfo( $blogUsers );
+ }
+
return $this->_usersInfo;
}
Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php 2005-02-26 22:26:32 UTC (rev 1220)
+++ plog/trunk/class/dao/blogs.class.php 2005-02-26 22:58:45 UTC (rev 1221)
@@ -94,29 +94,100 @@
$blogInfo->setOwnerInfo( $ownerInfo );
$blogInfo->setStatus( $query_result["status"] );
- if ($extended)
- {
- // this is a very particular case... there is no need to include all
- // the code in the SummaryStats class if we're only going to use it once :)
- $summaryStatsPath = PLOG_CLASS_PATH."class/summary/dao/summarystats.class.php";
- if( File::isReadable( $summaryStatsPath )) {
- include_once( $summaryStatsPath );
- $userpermissions = new UserPermissions();
- $stats = new SummaryStats();
+ return $blogInfo;
+ }
+
+ /**
+ * Retrieves the first article date timestamp
+ *
+ * @param blogId The identifier of the blog from which we'd like to fetch the settings
+ * @return Returns an Timestamp with the first article date
+ */
+ function getBlogCreateDate( $blogId )
+ {
+ $query = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date ASC LIMIT 0,1" ;
- $blogInfo->setCreateDate( $stats->getBlogCreateDate( $blogInfo->getId() ) );
- $blogInfo->setUpdateDate( $stats->getBlogUpdateDate( $blogInfo->getId() ) );
- $blogInfo->setTotalPosts( $stats->getBlogTotalPosts( $blogInfo->getId() ) );
- $blogInfo->setViewedTotal( $stats->getBlogViewedTotal( $blogInfo->getId() ) );
- }
- $blogUsers = $userpermissions->getBlogUsers( $blogInfo->getId());
- $blogInfo->setUsersInfo( $blogUsers );
- }
+ $result = $this->_db->Execute( $query );
- return $blogInfo;
+ if (!$result)
+ return false;
+
+ $row = $result->FetchRow();
+
+ if (!isset($row["date"]))
+ return false;
+
+ return $row["date"];
}
+
+ /**
+ * Retrieves the last article date timestamp
+ *
+ * @param blogId The identifier of the blog from which we'd like to fetch the settings
+ * @return Returns an Timestamp with the last article date
+ */
+ function getBlogUpdateDate( $blogId )
+ {
+ $query = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date DESC LIMIT 0,1" ;
+ $result = $this->_db->Execute( $query );
+ if (!$result)
+ return false;
+
+ $row = $result->FetchRow();
+
+ if (!isset($row["date"]))
+ return false;
+
+ return $row["date"];
+ }
+
/**
+ * Retrieves the total number of reads of all articles in that blog
+ *
+ * @param blogId The identifier of the blog from which we'd like to fetch the settings
+ * @return Returns an Timestamp with the last article date
+ */
+ function getBlogViewedTotal( $blogId )
+ {
+ $query = "SELECT SUM(num_reads) as total FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId;
+
+ $result = $this->_db->Execute( $query );
+
+ if (!$result)
+ return false;
+
+ $row = $result->FetchRow();
+
+ if (!isset($row["total"]))
+ return false;
+
+ return $row["total"];
+ }
+
+ /**
+ * Retrieves the total number of posts in a blog
+ *
+ * @param blogId The identifier of the blog from which we'd like to fetch the settings
+ * @return Returns an integer with the number of posts
+ */
+ function getBlogTotalPosts( $blogId )
+ {
+ $query = "SELECT COUNT(*) as total FROM ".$this->getPrefix()."articles WHERE blog_id = $blogId AND status = ".POST_STATUS_PUBLISHED;
+ $result = $this->_db->Execute( $query );
+
+ if (!$result)
+ return false;
+
+ $row = $result->FetchRow();
+
+ if (!isset($row["total"]))
+ return false;
+
+ return intval($row["total"]);
+ }
+
+ /**
* Retrieves the blog settings
*
* @param settingsField The contents of the blog_settings field from the database
Modified: plog/trunk/class/summary/dao/summarystats.class.php
===================================================================
--- plog/trunk/class/summary/dao/summarystats.class.php 2005-02-26 22:26:32 UTC (rev 1220)
+++ plog/trunk/class/summary/dao/summarystats.class.php 2005-02-26 22:58:45 UTC (rev 1221)
@@ -71,7 +71,7 @@
return $posts;
}
-
+
/**
* Returns an array with the most read articles
*
@@ -135,96 +135,6 @@
}
/**
- * Retrieves the first article date timestamp
- *
- * @param blogId The identifier of the blog from which we'd like to fetch the settings
- * @return Returns an Timestamp with the first article date
- */
- function getBlogCreateDate( $blogId )
- {
- $query = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date ASC LIMIT 0,1" ;
-
- $result = $this->_db->Execute( $query );
-
- if (!$result)
- return false;
-
- $row = $result->FetchRow();
-
- if (!isset($row["date"]))
- return false;
-
- return $row["date"];
- }
-
- /**
- * Retrieves the last article date timestamp
- *
- * @param blogId The identifier of the blog from which we'd like to fetch the settings
- * @return Returns an Timestamp with the last article date
- */
- function getBlogUpdateDate( $blogId )
- {
- $query = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date DESC LIMIT 0,1" ;
- $result = $this->_db->Execute( $query );
-
- if (!$result)
- return false;
-
- $row = $result->FetchRow();
-
- if (!isset($row["date"]))
- return false;
-
- return $row["date"];
- }
-
- /**
- * Retrieves the total number of reads of all articles in that blog
- *
- * @param blogId The identifier of the blog from which we'd like to fetch the settings
- * @return Returns an Timestamp with the last article date
- */
- function getBlogViewedTotal( $blogId )
- {
- $query = "SELECT SUM(num_reads) as total FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId;
-
- $result = $this->_db->Execute( $query );
-
- if (!$result)
- return false;
-
- $row = $result->FetchRow();
-
- if (!isset($row["total"]))
- return false;
-
- return $row["total"];
- }
-
- /**
- * Retrieves the total number of posts in a blog
- *
- * @param blogId The identifier of the blog from which we'd like to fetch the settings
- * @return Returns an integer with the number of posts
- */
- function getBlogTotalPosts( $blogId )
- {
- $query = "SELECT COUNT(*) as total FROM ".$this->getPrefix()."articles WHERE blog_id = $blogId AND status = ".POST_STATUS_PUBLISHED;
- $result = $this->_db->Execute( $query );
-
- if (!$result)
- return false;
-
- $row = $result->FetchRow();
-
- if (!isset($row["total"]))
- return false;
-
- return intval($row["total"]);
- }
-
- /**
*returns list with the most recently created blogs
*
* @param maxBlogs The maximum number of blogs to return, or '0' to get all of them
@@ -342,10 +252,6 @@
*/
function getRecentArticles( $maxPosts, $ignoreTopic = "", $ignoreText = "" )
{
- // get the list of categories that should be shown in the main page
- $articleCategories = new ArticleCategories();
- $allCategories = $articleCategories->getAllCategories( true );
-
$t = new Timestamp();
$date = $t->getTimestamp();
$prefix = $this->getPrefix();
@@ -354,7 +260,7 @@
a.user_id,a.blog_id, a.status, a.properties,
a.num_reads, a.slug
FROM {$prefix}articles a, {$prefix}articles_categories c, {$prefix}article_categories_link l,{$prefix}articles_text t
- WHERE t.article_id = a.id AND a.date <= NOW() AND l.article_id = a.id AND l.category_id = c.id AND
+ WHERE t.article_id = a.id AND TO_DAYS(NOW()) - TO_DAYS(a.date) < 7 AND l.article_id = a.id AND l.category_id = c.id AND
c.in_main_page = 1 AND a.status = ".POST_STATUS_PUBLISHED;
$this->log->debug($query);
More information about the pLog-svn
mailing list