a few preliminar changes, not working yet

This commit is contained in:
real_nowhereman 2008-09-06 10:10:30 +00:00
parent caa6e32751
commit dea2a2fa87
5 changed files with 136 additions and 94 deletions

View File

@ -2552,11 +2552,35 @@ class SBPlusWalker extends BPlusWalker {
function current_value() {
$id = parent::current_value();
return $this->tree->GETSTRING($id);
return $this->tree->getstring($id);
}
}
class caching_SBPT extends SBPlusTree {
var $cache = array();
function getitem($key) {
if (isset($cache[$key]))
return $cache[$key];
else return ($cache[$key] = parent::getitem($key));
}
function resetcache() {
$this->cache = array();
}
function nope() {
trigger_error("operation not permitted in caching_BPT", E_USER_WARNING);
}
function setitem() { $this->nope(); }
function delitem() { $this->nope(); }
}
class BPlusUtils {
function recopy_bplus($fromfile, $tofile, $class='BPlusTree') {

View File

@ -5,51 +5,44 @@
class cache_filelister extends fs_filelister {
var $_cachefile = null;
var $_offset = 0;
var $_nodesize = 30;
var $_keysize = 12;
// sub-classes will fill the above variables on constructing
function cache_filelister() {
if (!$this->_cachefile)
trigger_error('CACHE: no cache file specified');
trigger_error('CACHE: no cache file specified', E_USER_ERROR);
$varname = $this->_varname;
if (file_exists($this->_cachefile)) {
//include($this->_cachefile);
$var = io_load_file($this->_cachefile);
$this->_list = unserialize($var);
} else {
parent::fs_filelister();
$this->save();
}
return $this->_list;
if (!file_exists($this->_cachefile)) {
trigger_error ("Can't find index '{$this->_cachefile}'", E_USER_ERROR);
}
$this->_tree = caching_SBPT(
fopen($this->_cachefile.'.dat', 'r'),
fopen($this->_cachefile.'.strings.dat', 'r'),
$this->_offset,
$this->_chunksize,
$this->_keysize
);
#return $this->_list;
}
function checksorting() {
list($k1) = each($this->_list);
list($k2) = each($this->_list);
// decreasing order
if ((FP_SORTING==SORT_DESC) & (strcmp($k1, $k2) < 0)) {
$this->save;
}
function walker() {
return $this->_tree->walker();
}
function save() {
// TODO: re-think this :)
// reverse sorting on save is an acceptable overhead,
// still this is quite an hack
trigger_error('Cannot save() a cache', E_USER_ERROR);
/*
krsort($this->_list);
$succ = io_write_file($this->_cachefile, serialize($this->_list));
@ -61,24 +54,29 @@
} else return $this->_list;
*/
}
function getList() {
return $this->_list;
trigger_error('Cannot getlist from cache', E_USER_WARNING);
#return $this->_list;
}
function get($id) {
return isset($this->_list[$id])? $this->_list[$id] : false;
return $this->_tree->getitem($id);
#return isset($this->_list[$id])? $this->_list[$id] : false;
}
function add($id, $val) {
trigger_error('Cannot add to a cache', E_USER_ERROR) ;
$this->_list[$id]=$val;
return $this->save();
}
function delete($entryid) {
trigger_error('Cannot delete from a cache', E_USER_ERROR) ;
$cache =& $this->_list;
unset($cache[$entryid]); // if id found, it is deleted
@ -86,9 +84,10 @@
}
function purge() {
trigger_error('cannot purge', E_USER_ERROR);
return fs_delete($this->_cachefile);
}
}
?>
?>

View File

@ -1,8 +1,19 @@
<?php
class entry_indexer extends cache_filelister {
/**
* opens the index belonging to a given category
* @params int $id_cat
*/
function entry_indexer($id_cat=0) {
$this->_cachefile = 'index-'.$id_cat;
parent::cache_filelister();
}
}
class _entry_indexer extends cache_filelister {
var $_varname = 'cache';
var $_cachefile = null;
var $_directory = CONTENT_DIR;
@ -505,4 +516,4 @@
}
//add_action('init',
?>
?>

View File

@ -153,7 +153,7 @@
$fpdb->init();
$entry_index = $fpdb->entry_index;
$entry_index =& $fpdb->get_index($this->params->category);
if ($this->single) {
$this->_prepare_single($entry_index);
@ -202,21 +202,23 @@
}
function _prepare_list(&$entry_index) {
//global $blog_config;
$qp =& $this->params;
$entry_num = 0;
$this->walker =& $entry_index->walker();
if (!$qp->y){
$this->local_list = array_keys($entry_index);
$this->local_index =& $entry_index;
// searches the whole index
/* @todo MUST CACHE THIS COUNT! (MUST STRUCT CACHE)*/
$index_count = count($entry_index);
#$this->local_list = array_keys($entry_index);
$index_count = $entry_index->length();
} else {
// notice this won't work with cats (for now)
$obj =& new entry_archives($qp->y, $qp->m, $qp->d);
$filteredkeys = $obj->getList();
@ -227,53 +229,33 @@
}
if ($qp->count < 0) {
// count<0 means 'all'
$qp->count = $index_count;
} elseif (($qp->start + $qp->count) > $index_count) {
if ($index_count > 0)
$qp->count = $index_count - $qp->start;
else
$index_count = $qp->start = $qp->count = 0;
}
$this->pointer = $qp->start;
#$this->pointer = $qp->start;
// fills array
if ($qp->category==0)
return;
/* category */
/* this just SUCKS. need a separate cache... */
$relations = entry_categories_get('rels');
if (!isset($relations[$qp->category]))
return;
$catrel = $relations[$qp->category];
/* need to search for one more to know if we need a nextpage link */
$fill = $qp->start + $qp->count + 1;
$i = 0;
$tmp = array();
while ($i <= $fill && (list($K, $V) = each($this->local_list))) {
if (array_intersect($catrel, $this->local_index[$V]['categories'])) {
// in_array($qp->category, $this->local_index[$V]['categories']))
$tmp[] =& $this->local_list[$K];
$i++;
}
}
/*
stuff for cats, have a look
$this->local_list =& $tmp;
if ($qp->start + $qp->count > $i) {
$qp->count = $i - $qp->start;
}
*/
}
@ -331,14 +313,30 @@
$this->prepare();
$this->_fillPrevId();
$this->_fillNextId();
#$this->_fillPrevId();
#$this->_fillNextId();
$id = $this->_fillCurrentId();
#$id = $this->_fillCurrentId();
while ($this->walker->valid && $this->pointer<$qp->start) {
$this->previd = $this->currentid;
$id = $this->currentid = $this->walker->current_key();
$this->walker->next();
$this->pointer++;
}
// pointer == start
$this->previd = $this->currentid;
$id = $this->currentid = $this->walker->current_key();
if ($qp->fullparse && $this->counter <= 0) {
// full parse: reads the whole array from file
$cont = array();
$cont = entry_parse($id);
@ -348,12 +346,13 @@
$cont['comments'] = $this->comments->getCount();
/* index is updated with full-parsed entry */
$this->local_index[$id] = $cont;
#$this->local_index[$id] = $cont;
}
} else {
$cont = $this->local_index[$id];
// only title
$cont = array('subject' => $this->walker->current_value());
}
@ -373,9 +372,9 @@
return false;
$var =& $this->peekEntry();
$this->lastentry = $var;
$this->walker->next();
$this->pointer++;
return $var;
@ -521,7 +520,8 @@
class FPDB {
var $_indexer = null;
var $_indexer = array();
var $_categories = array();
var $queries = array();
@ -530,13 +530,21 @@
}
function init() {
if (!$this->_indexer) {
$this->_indexer =& new entry_indexer();
#if (!$this->_indexer) {
#$this->_indexer =& new entry_indexer();
$this->_categories = entry_categories_get();
$obj =& $this->_indexer;
$this->entry_index = $obj->getList();
#$obj =& $this->_indexer;
#$this->entry_index = $obj->getList();
#}
}
function &get_index($cat_id = 0) {
if (!isset($this->_indexer[$cat_id])) {
$this->_indexer[$cat_id] =& new entry_indexer($cat_id);
}
return $this->_indexer[$cat_id];
}
function reset($queryId=null) {

View File

@ -33,7 +33,7 @@
require_once INCLUDES_DIR.'core.static.php';
require_once INCLUDES_DIR.'core.draft.php';
require_once INCLUDES_DIR.'core.bplustree.class.php';
require_once INCLUDES_DIR.'core.fpdb.class.php';
require_once INCLUDES_DIR.'core.language.php';