diff --git a/defaults.php b/defaults.php index ed37d46..86e22e7 100755 --- a/defaults.php +++ b/defaults.php @@ -80,6 +80,8 @@ // cache file name and path. define('CACHE_DIR', FP_CONTENT . 'cache/'); define('CACHE_FILE', '%%cached_list.php'); + + define('INDEX_DIR', FP_CONTENT.'index/'); define('LOCKFILE', FP_CONTENT . '%%setup.lock'); diff --git a/fp-includes/core/core.cache.php b/fp-includes/core/core.cache.php index 2d1aa0e..a8af843 100755 --- a/fp-includes/core/core.cache.php +++ b/fp-includes/core/core.cache.php @@ -23,7 +23,7 @@ $this->_tree = caching_SBPT( fopen($this->_cachefile.'.dat', 'r'), - fopen($this->_cachefile.'.strings.dat', 'r'), + fopen(INDEX_DIR.'index.strings.dat', 'r'), $this->_offset, $this->_chunksize, $this->_keysize diff --git a/fp-includes/core/core.entry.php b/fp-includes/core/core.entry.php index 8abde9b..47fc8e2 100755 --- a/fp-includes/core/core.entry.php +++ b/fp-includes/core/core.entry.php @@ -1,15 +1,98 @@ _cachefile = 'index-'.$id_cat; + $this->_cachefile = INDEX_DIR.'index-'.$id_cat; parent::cache_filelister(); } + + } + + class entry_index { + + var $indices = array(); + var $_offset = 0; + var $_chunksize = 30; + var $_keysize = 12; + + + function entry_index() { + + // only main index s a SBPlus (string BPlus): + // the other (other categories) are managed + // as if they were simple BPlus trees, so + // values in key,value pairs won't + // be strings but integers + // + // the integer will be the seek position + // in the SBPlus' string file + // + // they'll be loaded back with the string file + // as SBPlus trees: the string-key, string-value pair + // will be returned + + $this->indices[0] = new SBPlusTree( + fopen(INDEX_DIR.'index-0.dat', 'r+'), + fopen(INDEX_DIR.'index.strings.dat', 'r+'), + $this->_offset, + $this->_chunksize, + $this->_keysize + ); + + + } + + function &get_index($cat=0) { + if (!isset($this->indices[$cat])) { + $this->indices[$cat] =& new BPlusTree( + fopen(INDEX_DIR.'index-'.$cat.'.dat', 'r+'), + $this->_offset, + $this->_chunksize, + $this->_keysize + ); + $this->indices[$cat]->open(); + } + return $this->indices[$cat]; + } + + function add($entry) { + $key =& entry_timetokey($entry['date']); + $val = $entry['subject']; + + $main =& $this->get_index(); + $seek = $main->setitem($key, $val); + + if (isset($entry['categories']) && is_array($entry['categories']) { + foreach ($entry['categories'] as $cat) { + if (!is_numeric($cat) continue; + $this_index =& $this->get_index($cat); + $this_index->setitem($key, $seek); + } + } + + } + + function delete($id) { + $key = entry_idtokey($id); + + $main =& $this->get_index(); + $main->delitem($key); + + if (isset($entry['categories']) && is_array($entry['categories']) { + foreach ($entry['categories'] as $cat) { + if (!is_numeric($cat) continue; + $this_index =& $this->get_index($cat); + $this_index->delitem($key); + } + } + + } + } class _entry_indexer extends cache_filelister { @@ -216,7 +299,21 @@ function entry_get() { $fpdb->get(); } - */ + */ + + function entry_keytoid($key) { + $date = substr($key,0,6); + $time = substr($key,6); + return "entry{$date}-{$time}"; + } + + function entry_idtokey($id) { + return substr($id, 5, 6) . substr($id, 11); + } + + function entry_timetokey($time) { + return date('ymdHis', $time); + } function entry_list() { diff --git a/fp-includes/core/core.fpdb.class.php b/fp-includes/core/core.fpdb.class.php index 6e6f0bc..165b5ab 100644 --- a/fp-includes/core/core.fpdb.class.php +++ b/fp-includes/core/core.fpdb.class.php @@ -322,7 +322,7 @@ while ($this->walker->valid && $this->pointer<$qp->start) { $this->previd = $this->currentid; - $id = $this->currentid = $this->walker->current_key(); + $id = $this->currentid = entry_keytoid($this->walker->current_key()); $this->walker->next(); $this->pointer++; @@ -542,7 +542,7 @@ function &get_index($cat_id = 0) { if (!isset($this->_indexer[$cat_id])) { - $this->_indexer[$cat_id] =& new entry_indexer($cat_id); + $this->_indexer[$cat_id] =& new entry_cached_index($cat_id); } return $this->_indexer[$cat_id]; } @@ -643,6 +643,28 @@ } } + + class FPDB_transaction { + + var $_index = null; + var $_offset = 0; + var $_nodesize = 30; + var $_keysize = 12; + + function FPDB_transaction($id_cat=0) { + $this->_index = INDEX_DIR.'index-'.$id_cat; + + $this->_tree = caching_SBPT( + fopen($this->_cachefile.'.dat', 'r'), + fopen($this->_cachefile.'.strings.dat', 'r'), + $this->_offset, + $this->_chunksize, + $this->_keysize + ); + + } + + } // SMARTY FUNCTIONS ----------------------------------------------------