openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit dfa62580abfed8c6859346e5ef07ec951f1603a9
parent 7173382255317525b6bc7554b637ba0b87124867
Author: dankert <devnull@localhost>
Date:   Tue, 11 Dec 2007 01:22:33 +0100

Cache von Dateien und Seiten zur Performancesteigerung beim Ver?ffentlichen.

Diffstat:
actionClasses/FileAction.class.php | 17++++++++---------
actionClasses/PageAction.class.php | 18++++++------------
config/cache.ini.php | 13+++++++++++++
objectClasses/File.class.php | 59++++++++++++++++++++++++++++++++++++++++++++++-------------
objectClasses/Object.class.php | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++----
objectClasses/Page.class.php | 46++++++++++++++++++++++++++++++++++++++--------
objectClasses/Value.class.php | 46++++++++++++++++++++++++++++++++++++++--------
7 files changed, 203 insertions(+), 54 deletions(-)

diff --git a/actionClasses/FileAction.class.php b/actionClasses/FileAction.class.php @@ -128,13 +128,15 @@ class FileAction extends ObjectAction header('Content-Transfer-Encoding: binary' ); header('Content-Description: '.$this->file->name ); - $this->file->loadValue(); // Bild aus Datenbank laden + $this->file->write(); // Bild aus Datenbank laden // Groesse des Bildes in Bytes // Der Browser hat so die Moeglichkeit, einen Fortschrittsbalken zu zeigen - header('Content-Length: '.strlen($this->file->value) ); - - echo $this->file->value; + header('Content-Length: '.filesize($this->file->tmpfile()) ); + + + + readfile( $this->file->tmpfile() ); exit; } @@ -560,11 +562,8 @@ class FileAction extends ObjectAction $this->file->publish(); $this->file->publish->close(); - foreach( $this->file->publish->publishedObjects as $o ) - { - $this->addNotice($o['type'],$o['full_filename'],'PUBLISHED','ok'); - } - + $this->addNotice('file',$this->file->fullFilename,'PUBLISHED',$this->file->publish->ok?OR_NOTICE_OK:OR_NOTICE_ERROR,array(),$this->file->publish->log); + $this->callSubaction('pub'); } diff --git a/actionClasses/PageAction.class.php b/actionClasses/PageAction.class.php @@ -555,13 +555,7 @@ class PageAction extends ObjectAction $language = Session::getProjectLanguage(); header('Content-Language: '.$language->isoCode); - require( $this->page->tmpfile ); - - - unlink( $this->page->tmpfile ); - - // Inhalt ist ausgegeben... Skript beenden. - exit; + require( $this->page->tmpfile() ); } @@ -750,12 +744,12 @@ class PageAction extends ObjectAction $this->page->publish(); $this->page->publish->close(); - foreach( $this->page->publish->publishedObjects as $o ) - { - $this->addNotice($o['type'],$o['full_filename'],'PUBLISHED','ok'); - } +// foreach( $this->page->publish->publishedObjects as $o ) +// { +// $this->addNotice($o['type'],$o['full_filename'],'PUBLISHED','ok'); +// } - $this->addNotice($o['type'],$o['full_filename'],'PUBLISHED','ok',array(),$this->page->publish->log); + $this->addNotice('page',$this->page->fullFilename,'PUBLISHED',$this->page->publish->ok?OR_NOTICE_OK:OR_NOTICE_ERROR,array(),$this->page->publish->log); $this->callSubaction('pub'); } diff --git a/config/cache.ini.php b/config/cache.ini.php @@ -4,3 +4,15 @@ ; This is much faster, but sometimes caching is unwanted ; if you have caching problems, set this to 'false'. Default: 'true' conditional_get=true + + + +; Pages and files are cached in a temporary directory. +; Leave this to "true", as it will improve the performance. +enable_cache=true + + + +; Directory for temporary files. +; Default=blank (OpenRat uses the system temporary dir) +tmp_dir=+ \ No newline at end of file diff --git a/objectClasses/File.class.php b/objectClasses/File.class.php @@ -518,9 +518,14 @@ EOF } - // Lesen der Datei aus der Datenbank + /** + * Lesen der Datei aus der Datenbank. + */ function loadValue() - { + { + if ( is_file($this->tmpfile())) + return implode('',file($this->tmpfile())); // From cache + $db = db_connection(); $sql = new Sql( 'SELECT size,value'. @@ -537,12 +542,19 @@ EOF if ( $this->storeValueAsBase64 ) $this->value = base64_decode( $this->value ); - + + // Store in cache. + $f = fopen( $this->tmpfile(),'w' ); + fwrite( $f,$this->value ); + fclose( $f ); + return $this->value; } - // Lesen der Datei aus der Datenbank + /** + * Speichert den Inhalt in der Datenbank. + */ function saveValue( $value = '' ) { $db = db_connection(); @@ -555,19 +567,21 @@ EOF $sql->setInt ( 'size' ,strlen($this->value) ); if ( $this->storeValueAsBase64 ) - $sql->setString( 'value' ,base64_encode($this->value) ); - else $sql->setString( 'value' ,$this->value ); + $sql->setString( 'value',base64_encode($this->value) ); + else + $sql->setString( 'value',$this->value ); $db->query( $sql->query ); } - // Lesen der Datei aus der Datenbank und schreiben in temporaere Datei + /** + * Lesen der Datei aus der Datenbank und schreiben in temporaere Datei + */ function write() - { - $f = fopen( $this->tmpfile(),'w' ); - fwrite( $f,$this->loadValue() ); - fclose( $f ); + { + if ( !is_file($this->tmpfile()) ) + $this->loadValue(); } @@ -600,10 +614,29 @@ EOF $this->write(); $this->publish->copy( $this->tmpfile(),$this->full_filename() ); - unlink( $this->tmpfile ); $this->publish->publishedObjects[] = $this->getProperties(); - } + } + + + /** + * Ermittelt einen temporären Dateinamen für diese Datei. + */ + function tmpfile() + { + $db = db_connection(); + $filename = $this->getTempDir().'/openrat_db'.$db->id.'_'.$this->objectid.'.tmp'; + return $filename; + } + + + function setTimestamp() + { + unlink( $this->tmpfile() ); + + $parent->setTimestamp(); + } + } ?> \ No newline at end of file diff --git a/objectClasses/Object.class.php b/objectClasses/Object.class.php @@ -20,6 +20,9 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // --------------------------------------------------------------------------- // $Log$ +// Revision 1.28 2007-12-11 00:22:31 dankert +// Cache von Dateien und Seiten zur Performancesteigerung beim Ver?ffentlichen. +// // Revision 1.27 2007-12-01 17:49:37 dankert // Methode "available()" ergibt sofort "false", wenn Objekt-Id ung?ltig (Performance) // @@ -1071,13 +1074,33 @@ class Object /** * Dateinamen der temporaeren Datei bestimmen */ - function tmpfile() + function tmpfileYYYYYY() { if ( isset($this->tmpfile) && $this->tmpfile != '' ) - return $this->tmpfile; + return $this->tmpfile; // Temporärer Dateiname bereits vorhanden. + + global $conf; + + // 1. Versuch: Temp-Dir aus Konfiguration. + $tmpdir = @$conf['cache']['tmp_dir']; + if ( $this->tmpfile === FALSE ) + $this->tmpfile = @tempnam( $tmpdir,'openrat_tmp' ); - $tmpdir = ini_get('upload_tmp_dir'); - $this->tmpfile = tempnam( $tmpdir,'openrat_tmp' ); + // 2. Versuch: Temp-Dir aus "upload_tmp_dir". + if ( $this->tmpfile === FALSE ) + { + Html::debug($this->tmpfile,"nochmal"); + $tmpdir = ini_get('upload_tmp_dir'); + $this->tmpfile = @tempnam( $tmpdir,'openrat_tmp' ); + } + + elseif ( $this->tmpfile === FALSE ) + { + Html::debug($this->tmpfile,"nochmal"); + $this->tmpfile = @tempnam( '','openrat_tmp' ); + } + + Html::debug($this->tmpfile,"tmpfile in objekt"); Logger::debug( 'creating temporary file: '.$this->tmpfile ); return $this->tmpfile; @@ -1085,6 +1108,33 @@ class Object /** + * Dateinamen der temporaeren Datei bestimmen + */ + function getTempDir() + { + $tmpdir = @$conf['cache']['tmp_dir']; + $tmpfile = @tempnam( $tmpdir,'openrat_tmp' ); + + // 2. Versuch: Temp-Dir aus "upload_tmp_dir". + if ( $tmpfile === FALSE ) + { + $tmpdir = ini_get('upload_tmp_dir'); + $tmpfile = @tempnam( $tmpdir,'openrat_tmp' ); + } + + elseif ( $tmpfile === FALSE ) + { + $tmpfile = @tempnam( '','openrat_tmp' ); + } + + $tmpdir = dirname($tmpfile); + @unlink($tmpfile); + + return $tmpdir; + } + + + /** * Reihenfolge-Sequenznr. dieses Objektes neu speichern * die Nr. wird sofort in der Datenbank gespeichert. * diff --git a/objectClasses/Page.class.php b/objectClasses/Page.class.php @@ -20,6 +20,9 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // --------------------------------------------------------------------------- // $Log$ +// Revision 1.25 2007-12-11 00:22:31 dankert +// Cache von Dateien und Seiten zur Performancesteigerung beim Ver?ffentlichen. +// // Revision 1.24 2007-11-24 14:18:12 dankert // MimeType in Template ermitteln. // @@ -722,7 +725,12 @@ class Page extends Object */ function generate() { - + if ( is_file($this->tmpfile() )) + { + $this->value = implode('',file($this->tmpfile())); + return $this->value; + } + global $conf, $conf_php, $db, @@ -772,7 +780,12 @@ class Page extends Object } $this->value = &$src; - + + // Store in cache. + $f = fopen( $this->tmpfile(),'w' ); + fwrite( $f,$this->value ); + fclose( $f ); + return $this->value; } @@ -782,12 +795,8 @@ class Page extends Object */ function write() { - // Schreiben der Cache-Datei - // - - $f = fopen( $this->tmpfile(),'a' ); - fwrite( $f,$this->value ); - fclose( $f ); + if ( !is_file($this->tmpfile())) + $this->generate(); } @@ -855,6 +864,27 @@ class Page extends Object return( $this->mime_type ); } + + + + /** + * Ermittelt einen temporären Dateinamen für diese Seite. + */ + function tmpfile() + { + $db = db_connection(); + $filename = $this->getTempDir().'/openrat_db'.$db->id.'_o'.$this->objectid.'_l'.$this->languageid.'_m'.$this->modelid.'.tmp'; + return $filename; + } + + + + function setTimestamp() + { + unlink( $this->tmpfile() ); + + $parent->setTimestamp(); + } } diff --git a/objectClasses/Value.class.php b/objectClasses/Value.class.php @@ -429,6 +429,12 @@ SQL $inhalt = ''; + if ( is_file( $this->tmpfile() )) + { + $this->value = implode('',file($this->tmpfile() )); // from cache. + return; + } + // Inhalt ist mit anderer Seite verknüpft. if ( in_array($this->element->type,array('text','longtext','date','number')) && intval($this->linkToObjectId) != 0 && !$this->isLink ) { @@ -1106,6 +1112,12 @@ SQL $inhalt = '<a href="'.Html::url('pageelement','edit',$this->page->objectid,array('elementid'=>$this->element->elementid)).'" title="'.$this->element->desc.'" target="cms_main_main"><img src="'.OR_THEMES_DIR.$conf['interface']['theme'].'/images/icon_el_'.$this->element->type.IMG_ICON_EXT.'" border="0" align="left"></a>'.$inhalt; $this->value = $inhalt; + + + // Store in cache. + $f = fopen( $this->tmpfile(),'w' ); + fwrite( $f,$this->value ); + fclose( $f ); } @@ -1168,15 +1180,33 @@ SQL { $db = db_connection(); - $sql = new Sql( 'SELECT {t_object}.id FROM {t_value} '. - ' LEFT JOIN {t_page} '. - ' ON {t_page}.id={t_value}.pageid '. - ' LEFT JOIN {t_object} '. - ' ON {t_object}.id={t_page}.objectid '. - ' WHERE {t_value}.lastchange_userid={userid}'. - ' ORDER BY {t_object}.lastchange_date DESC' ); + $sql = new Sql( <<<SQL +SELECT {t_object}.id + FROM {t_value} + LEFT JOIN {t_page} + ON {t_page}.id={t_value}.pageid + LEFT JOIN {t_object} + ON {t_object}.id={t_page}.objectid + WHERE {t_value}.lastchange_userid={userid} + ORDER BY {t_value}.lastchange_date DESC +SQL +); $sql->setInt ( 'userid' ,$userid ); - return $db->getOne( $sql->query ); } + + + /** + * Ermittelt einen temporären Dateinamen für diesen Inhalt. + */ + function tmpfile() + { + $db = db_connection(); + $filename = Object::getTempDir().'/openrat_db'.$db->id.'_p'.$this->pageid.'_v'.$this->valueid.'_e'.$this->element->elementid.'_l'.$this->languageid.'_s'.intval($this->simple).'.tmp'; + return $filename; + } + + + + } \ No newline at end of file