[pLog-svn] r1934 - in plog/branches/plog-1.1-ben/class: cache
gallery/dao
ork at devel.plogworld.net
ork at devel.plogworld.net
Tue May 3 18:49:22 GMT 2005
Author: ork
Date: 2005-05-03 18:49:21 +0000 (Tue, 03 May 2005)
New Revision: 1934
Modified:
plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php
plog/branches/plog-1.1-ben/class/gallery/dao/galleryalbums.class.php
plog/branches/plog-1.1-ben/class/gallery/dao/galleryresources.class.php
Log:
activated caching of useralbums, galleryalbum and resources ..
Modified: plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php 2005-05-03 18:46:41 UTC (rev 1933)
+++ plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php 2005-05-03 18:49:21 UTC (rev 1934)
@@ -5,6 +5,9 @@
define( "CACHE_GLOBAL", "pLog" );
define( "CACHE_LOCALES", "locales" );
+ define( "CACHE_RESOURCES", "resources" );
+ define( "CACHE_GALLERYALBUM", "album" );
+ define( "CACHE_USERALBUMS", "useralbums" );
define( "CACHE_USERINFO", "userinfo" );
define( "CACHE_USERIDBYNAME", "userinfo_idbyname" );
define( "CACHE_BLOGINFOS", "bloginfo" );
Modified: plog/branches/plog-1.1-ben/class/gallery/dao/galleryalbums.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/gallery/dao/galleryalbums.class.php 2005-05-03 18:46:41 UTC (rev 1933)
+++ plog/branches/plog-1.1-ben/class/gallery/dao/galleryalbums.class.php 2005-05-03 18:49:21 UTC (rev 1934)
@@ -78,19 +78,25 @@
*/
function getAlbum( $id, $ownerId = -1, $fetchResources = true, $onlyShownAlbums = false )
{
- // make sure that we don't have this album yet...
+ // we might have this album in the memory cache already..
if( isset($this->cache[$id])) {
return $this->cache[$id];
}
- // otherwise, continue the normal process...
- $query = "SELECT * FROM ".$this->getPrefix()."gallery_albums WHERE id = $id";
- if( $ownerId != -1 )
- $query .= " AND owner_id = $ownerId";
- if( $onlyShownAlbums )
- $query .= " AND show_album = 1";
-
- return $this->_getAlbumFromQuery( $query );
+ // or in the global file cache..
+ $album = $this->_cache->getData( $id, CACHE_GALLERYALBUM );
+
+ if ( !$album || ($onlyShownAlbums && !$album->getShowAlbum()) ) {
+ // otherwise, continue the normal process...
+ $query = "SELECT * FROM ".$this->getPrefix()."gallery_albums WHERE id = $id";
+ if( $ownerId != -1 )
+ $query .= " AND owner_id = $ownerId";
+ if( $onlyShownAlbums )
+ $query .= " AND show_album = 1";
+ $album = $this->_getAlbumFromQuery( $query );
+ $this->_cache->setData( $id, CACHE_GALLERYALBUM, $album );
+ }
+ return $album;
}
/**
@@ -214,6 +220,9 @@
// return the id of the last row we inserted, which will be the id of the album
$result = $this->_db->Insert_ID();
+
+ // remove the cached album hierarchy array
+ $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS );
return $result;
}
@@ -245,8 +254,8 @@
if ($album->getId() == $album->getParentId()){
return false;
}
- $tf = new TextFilter();
- $query = "UPDATE ".$this->getPrefix()."gallery_albums SET
+ $tf = new TextFilter();
+ $query = "UPDATE ".$this->getPrefix()."gallery_albums SET
description = '".Db::qstr($album->getDescription())."',
name = '".Db::qstr($album->getName())."',
parent_id = ".$album->getParentId().",
@@ -257,7 +266,13 @@
mangled_name = '".$tf->urlize($album->getName())."'
WHERE id = ".$album->getId().";";
- return $this->Execute( $query );
+ // remove the album from the cache
+ $this->_cache->removeData( $album->getId(), CACHE_GALLERYALBUM );
+
+ // and remove the cached album hierarchy array
+ $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS );
+
+ return $this->Execute( $query );
}
/**
@@ -269,11 +284,20 @@
*/
function deleteAlbum( $albumId, $userId = -1 )
{
+ // remove the cached album hierarchy array 1st ..
+ // too bad we need to load the album before deleting it, but this method
+ // won't get called all to often anyway :)
+ $album = $this->getAlbum( $albumId );
+ $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS );
+
$query = "DELETE FROM ".$this->getPrefix()."gallery_albums
WHERE id = $albumId";
if( $userId != -1 )
$query .= " AND owner_id = $userId";
+ // remove the album from the cache
+ $this->_cache->removeData( $albumId, CACHE_GALLERYALBUM );
+
return $this->Execute( $query );
}
@@ -348,42 +372,47 @@
* array with all the albums that share the same parent id or empty if none
*
* @param userId
- * @param albumId
+ * @param albumId - unused
* @return An associative array
*/
function getUserAlbumsGroupedByParentId( $userId, $albumId = 0 )
{
- $prefix = $this->getPrefix();
- $query = "SELECT * FROM {$prefix}gallery_albums
- WHERE owner_id = '".Db::qstr($userId)."'
- ORDER BY name ASC";
+ $albums = $this->_cache->getData( $userId, CACHE_USERALBUMS );
- $result = $this->Execute( $query );
+ if ( !$albums ) {
+ $prefix = $this->getPrefix();
+ $query = "SELECT * FROM {$prefix}gallery_albums
+ WHERE owner_id = '".Db::qstr($userId)."'
+ ORDER BY name ASC";
+
+ $result = $this->Execute( $query );
+
+ if( !$result )
+ return Array();
+
+ $albums = Array();
+ $ids = Array();
+ $ids[] = 0;
+ while( $row = $result->FetchRow()) {
+ $album = new GalleryAlbum( $row["owner_id"],
+ $row["name"],
+ $row["description"],
+ $row["flags"],
+ $row["parent_id"],
+ $row["date"],
+ unserialize($row["properties"]),
+ $row["show_album"],
+ $row["id"] );
+ $key = $album->getParentId();
+ if( $albums["$key"] == "" )
+ $albums["$key"] = Array();
+ $albums["$key"][] = $album;
+
+ $ids[] = $album->getId();
+ }
+ $this->_cache->setData( $userId, CACHE_USERALBUMS, $albums );
+ }
- if( !$result )
- return Array();
-
- $albums = Array();
- $ids = Array();
- $ids[] = 0;
- while( $row = $result->FetchRow()) {
- $album = new GalleryAlbum( $row["owner_id"],
- $row["name"],
- $row["description"],
- $row["flags"],
- $row["parent_id"],
- $row["date"],
- unserialize($row["properties"]),
- $row["show_album"],
- $row["id"] );
- $key = $album->getParentId();
- if( $albums["$key"] == "" )
- $albums["$key"] = Array();
- $albums["$key"][] = $album;
-
- $ids[] = $album->getId();
- }
-
return $albums;
}
@@ -456,4 +485,4 @@
return $album;
}
}
-?>
\ No newline at end of file
+?>
Modified: plog/branches/plog-1.1-ben/class/gallery/dao/galleryresources.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/gallery/dao/galleryresources.class.php 2005-05-03 18:46:41 UTC (rev 1933)
+++ plog/branches/plog-1.1-ben/class/gallery/dao/galleryresources.class.php 2005-05-03 18:49:21 UTC (rev 1934)
@@ -92,23 +92,28 @@
*/
function getResource( $resourceId, $ownerId = -1, $albumId = -1 )
{
- $query = "SELECT * FROM ".$this->getPrefix()."gallery_resources
- WHERE id = $resourceId";
- if( $ownerId > 0 )
- $query .= " AND owner_id = $ownerId";
- if( $albumId > 0 )
- $query .=" AND album_id = $albumId";
+ $resource = $this->_cache->getData( $resourceId, CACHE_RESOURCES );
- $result = $this->Execute( $query );
+ if( !$resource ) {
+ $query = "SELECT * FROM ".$this->getPrefix()."gallery_resources
+ WHERE id = $resourceId";
+ if( $ownerId > 0 )
+ $query .= " AND owner_id = $ownerId";
+ if( $albumId > 0 )
+ $query .=" AND album_id = $albumId";
- if( !$result )
- return false;
+ $result = $this->Execute( $query );
- if( $result->RecordCount() == 0 )
- return false;
+ if( !$result )
+ return false;
- $row = $result->FetchRow();
- $resource = $this->_fillResourceInformation( $row );
+ if( $result->RecordCount() == 0 )
+ return false;
+
+ $row = $result->FetchRow();
+ $resource = $this->_fillResourceInformation( $row );
+ $this->_cache->setData( $resourceId, CACHE_RESOURCES, $resource );
+ }
return $resource;
}
@@ -618,6 +623,9 @@
$result = $this->Execute( $query );
+ // clear the cache
+ $this->_cache->removeData( $resource->getId(), CACHE_RESOURCES );
+
if( !$result )
return false;
else
@@ -643,6 +651,9 @@
$query .= " AND owner_id = $ownerId";
$result = $this->Execute( $query );
+
+ // clear the cache
+ $this->_cache->removeData( $resourceId, CACHE_RESOURCES );
// if there was an error, we quit here
if( !$result )
More information about the pLog-svn
mailing list