Thread: [Phpfreechat-svn] SF.net SVN: phpfreechat: [524] trunk/src/pfccontainer.class.php
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-05-28 15:54:42
|
Revision: 524 Author: kerphi Date: 2006-05-28 08:54:34 -0700 (Sun, 28 May 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=524&view=rev Log Message: ----------- pfcContainer interface and documentation update Modified Paths: -------------- trunk/src/pfccontainer.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2006-05-28 15:46:57 UTC (rev 523) +++ trunk/src/pfccontainer.class.php 2006-05-28 15:54:34 UTC (rev 524) @@ -36,7 +36,7 @@ /** * Create (connect/join) the nickname into the server or the channel locations - * Notice: this function must update all channels the users joined (use stored channel list into metadata) + * Notice: the caller must take care to update all channels the users joined (use stored channel list into metadata) * @param $chan if NULL then create the user on the server (connect), otherwise create the user on the given channel (join) * @param $nick the nickname to create * @param $nickid is the corresponding nickname id (taken from session) @@ -46,9 +46,10 @@ /** * Remove (disconnect/quit) the nickname from the server or from a channel - * Notice: this function must update all channels if the user disconnect completly (use stored channel list into metadata) - * @param $chan if NULL then remove the user on the server (disconnect) and on all the joined channels, otherwise just remove the user from the given channel (quit) + * Notice: The caller must take care to update all joined channels. + * @param $chan if NULL then remove the user on the server (disconnect), otherwise just remove the user from the given channel (quit) * @param $nick the nickname to remove + * @return true if the nickname was correctly removed */ function removeNick($chan, $nickname) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } @@ -62,9 +63,11 @@ function updateNick($chan, $nick) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } + /** * Change the user' nickname - * Notice: this function must update all channels the users joined (use stored channel list into metadata) + * Notice: this call must take care to update all channels the user joined + * @param $chan where to update the nick, if null then update the server nick * @param $newnick * @param $oldnick */ @@ -85,7 +88,7 @@ * Notice: this function must remove all nicknames which are not uptodate from the given channel or from the server * @param $chan if NULL then check obsolete nick on the server, otherwise just check obsolete nick on the given channel * @param $timeout - * @return array() contains all disconnected nicknames + * @return array("nick"=>???, "timestamp"=>???) contains all disconnected nicknames and there timestamp */ function removeObsoleteNick($chan, $timeout) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } @@ -93,26 +96,37 @@ /** * Returns the nickname list on the given channel or on the whole server * @param $chan if NULL then returns all connected user, otherwise just returns the channel nicknames - * @return array() contains a nickname list - */ + * @return array(array("nick"=>???,"timestamp"=>???) contains the nickname list with the associated timestamp (laste update time) + */ function getOnlineNick($chan) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } /** - * Write a message to the given channel or to the server + * Returns returns a positive number if the nick is online + * @param $chan if NULL then check if the user is online on the server, otherwise check if the user has joined the channel + * @return -1 if the user is off line, a positive (>=0) if the user is online + */ + function isNickOnline($chan, $nick) + { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } + + /** + * Write a command to the given channel or to the server * Notice: a message is very generic, it can be a misc command (notice, me, ...) * @param $chan if NULL then write the message on the server, otherwise just write the message on the channel message pool * @param $nick is the sender nickname - * @param $msg is the raw message to write + * @param $cmd is the command name (ex: "send", "nick", "kick" ...) + * @param $param is the command' parameters (ex: param of the "send" command is the message) + * @return $msg_id the created message identifier */ function write($chan, $nick, $msg) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } /** - * Read the last posted messages from a channel or from the server + * Read the last posted commands from a channel or from the server + * Notice: the returned array must be ordered by id * @param $chan if NULL then read from the server, otherwise read from the given channel * @param $from_id read all message with a greater id - * @return array() contains the messages list + * @return array() contains the command list */ function read($chan, $from_id) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } @@ -123,7 +137,7 @@ * @param $chan if NULL then read if from the server, otherwise read if from the given channel * @return int is the last posted message id */ - function getLastMsgId() + function getLastId($chan) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } /** @@ -132,7 +146,7 @@ * @param $key is the index which identify a metadata * @param $type is used to "group" some metadata * @param $subtype is used to "group" precisely some metadata, use NULL to ignore it - * @return mixed the value assigned to the key + * @return mixed the value assigned to the key, NULL if not found */ function getMeta($key, $type, $subtype = NULL) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } @@ -144,15 +158,18 @@ * @param $value is the value associated to the key * @param $type is used to "group" some metadata * @param $subtype is used to "group" precisely some metadata, use NULL to ignore it + * @return true on success, false on error */ - function setMeta($key, $value, $type, $subtype = NULL) + function setMeta($value, $key, $type, $subtype = NULL) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } + /** * Remove a meta data key/value couple * Notice: if key is NULL then all the meta data must be removed * @param $key is the key to delete, use NULL to delete all the metadata * @param $type is used to "group" some metadata * @param $subtype is used to "group" precisely some metadata, use NULL to ignore it + * @return true on success, false on error */ function rmMeta($key, $type, $subtype = NULL) { die(_pfc("%s must be implemented", get_class($this)."::".__FUNCTION__)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-12-19 22:35:24
|
Revision: 904 http://svn.sourceforge.net/phpfreechat/?rev=904&view=rev Author: kerphi Date: 2006-12-19 14:35:09 -0800 (Tue, 19 Dec 2006) Log Message: ----------- Container optimization: add a memory cache (work in progress) Modified Paths: -------------- trunk/src/pfccontainer.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2006-12-19 22:32:45 UTC (rev 903) +++ trunk/src/pfccontainer.class.php 2006-12-19 22:35:09 UTC (rev 904) @@ -289,7 +289,7 @@ { if ($chan == NULL) $chan = 'SERVER'; - $ret = $this->getMeta("channelid-to-nickid", $this->encode($chan)); + $ret = $this->getMeta("channelid-to-nickid", $this->encode($chan)); for($i = 0; $i<count($ret['timestamp']); $i++) { if ($ret['value'][$i] == $nickid) return $i; @@ -493,17 +493,22 @@ { $ret = $this->_container->setMeta($group, $subgroup, $leaf, $leafvalue); - echo "setMeta($group, $subgroup, $leaf, $leafvalue)\n"; - //print_r($ret); + // echo "setMeta($group, $subgroup, $leaf, $leafvalue)\n"; - - // @todo creer la bonne hierarchie du cache - - //$this->_cache['group'][$group] = array_merge($this->_cache['group'][$group],array($subgroup)); - //$this->_cache[$group][$subgroup][$leaf] = $leafvalue; - - //$this->_cache['subgroup'][$group][$subgroup] = $ret; - //$this->_cache['leaf'][$group][$subgroup][$leaf] = ($withleafvalue ? ; + if (isset($this->_cache[$group]['value']) && + !in_array($subgroup, $this->_cache[$group]['value'])) + { + $this->_cache[$group]['value'][] = $subgroup; + $this->_cache[$group]['timestamp'][] = time(); + } + if (isset($this->_cache[$group]['childs'][$subgroup]['value']) && + !in_array($leaf, $this->_cache[$group]['childs'][$subgroup]['value'])) + { + $this->_cache[$group]['childs'][$subgroup]['value'][] = $leaf; + $this->_cache[$group]['childs'][$subgroup]['timestamp'][] = time(); + } + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = array($leafvalue); + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = array(time()); return $ret; } @@ -519,52 +524,58 @@ */ function getMeta($group, $subgroup = null, $leaf = null, $withleafvalue = false) { - echo "getMeta($group, $subgroup, $leaf, $withleafvalue)\n"; + $ret = array('timestamp' => array(), + 'value' => array()); + // check in the cache - $ret = array('timestamp' => array(), - 'value' => array()); + $incache = false; if ($subgroup == null && isset($this->_cache[$group]['value'])) { - $ret['timestamp'] = $this->_cache[$group]['timestamp']; - $ret['value'] = $this->_cache[$group]['value']; - echo "getMeta->incache\n"; - return $ret; + $incache = true; + $ret = $this->_cache[$group]; } else if ($leaf == null && - isset($this->_cache[$group][$subgroup]['value'])) + isset($this->_cache[$group]['childs'][$subgroup]['value'])) { - $ret['timestamp'] = $this->_cache[$group][$subgroup]['timestamp']; - $ret['value'] = $this->_cache[$group][$subgroup]['value']; - echo "getMeta->incache\n"; - return $ret; + $incache = true; + $ret = $this->_cache[$group]['childs'][$subgroup]; } else { if ($withleafvalue) { - if (isset($this->_cache[$group][$subgroup][$leaf]['value'])) + if (isset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'])) { - echo "getMeta->incache\n"; - return $this->_cache[$group][$subgroup][$leaf]; + $incache = true; + $ret = $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]; } } else { - if (isset($this->_cache[$group][$subgroup][$leaf]['timestamp'])) + if (isset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'])) { - echo "getMeta->incache\n"; - return $this->_cache[$group][$subgroup][$leaf]; + $incache = true; + $ret = $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]; } } } - echo "getMeta->notincache\n"; + // echo "getMeta($group, $subgroup, $leaf, $withleafvalue)".($incache?"incache":"notincache")."\n"; + + if ($incache) + { + $ret = array('timestamp' => $ret['timestamp'], + 'value' => $ret['value']); + return $ret; + } + // get the fresh data $ret = $this->_container->getMeta($group, $subgroup, $leaf, $withleafvalue); + // store in the cache if ($subgroup == null) { @@ -573,14 +584,16 @@ } else if ($leaf == null) { - $this->_cache[$group][$subgroup]['value'] = $ret['value']; - $this->_cache[$group][$subgroup]['timestamp'] = $ret['timestamp']; + $this->_cache[$group]['childs'][$subgroup]['value'] = $ret['value']; + $this->_cache[$group]['childs'][$subgroup]['timestamp'] = $ret['timestamp']; } else { if ($withleafvalue) - $this->_cache[$group][$subgroup][$leaf]['value'] = $ret['value']; - $this->_cache[$group][$subgroup][$leaf]['timestamp'] = $ret['timestamp']; + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = $ret['value']; + else + unset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value']); + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = $ret['timestamp']; } return $ret; @@ -596,21 +609,45 @@ */ function rmMeta($group, $subgroup = null, $leaf = null) { - echo "rmMeta($group, $subgroup, $leaf)\n"; - - print_r($this->_cache); + //echo "rmMeta($group, $subgroup, $leaf)\n"; + // if ($group == "channelid-to-nickid") + // { echo "avant\n"; print_r($this->_cache[$group]); } + // remove from the cache if ($group == null) $this->_cache = array(); else if ($subgroup == null) unset($this->_cache[$group]); else if ($leaf == null) - unset($this->_cache[$group][$subgroup]); + { + if (isset($this->_cache[$group]['value'])) + { + $i = array_search($subgroup,$this->_cache[$group]['value']); + if ($i !== FALSE) + { + unset($this->_cache[$group]['value'][$i]); + unset($this->_cache[$group]['timestamp'][$i]); + } + } + unset($this->_cache[$group]['childs'][$subgroup]); + } else - unset($this->_cache[$group][$subgroup][$leaf]); + { + if (isset($this->_cache[$group]['childs'][$subgroup]['value'])) + { + $i = array_search($leaf,$this->_cache[$group]['childs'][$subgroup]['value']); + if ($i !== FALSE) + { + unset($this->_cache[$group]['childs'][$subgroup]['value'][$i]); + unset($this->_cache[$group]['childs'][$subgroup]['timestamp'][$i]); + } + } + unset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]); + } - print_r($this->_cache); + // if ($group == "channelid-to-nickid") + // { echo "apres\n"; print_r($this->_cache[$group]); } return $this->_container->rmMeta($group, $subgroup, $leaf); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-01-31 09:11:44
|
Revision: 939 http://svn.sourceforge.net/phpfreechat/?rev=939&view=rev Author: kerphi Date: 2007-01-31 01:11:44 -0800 (Wed, 31 Jan 2007) Log Message: ----------- comment clarification Modified Paths: -------------- trunk/src/pfccontainer.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-01-31 08:43:24 UTC (rev 938) +++ trunk/src/pfccontainer.class.php 2007-01-31 09:11:44 UTC (rev 939) @@ -284,7 +284,7 @@ } /** - * Returns returns a positive number if the nick is online + * Returns returns a positive number if the nick is online in the given channel * @param $chan if NULL then check if the user is online on the server, otherwise check if the user has joined the channel * @return -1 if the user is off line, a positive (>=0) if the user is online */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-08-06 15:18:50
|
Revision: 1089 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1089&view=rev Author: kerphi Date: 2007-08-06 08:18:53 -0700 (Mon, 06 Aug 2007) Log Message: ----------- Oups the incMeta code was duplicated Modified Paths: -------------- trunk/src/pfccontainer.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-06 14:52:30 UTC (rev 1088) +++ trunk/src/pfccontainer.class.php 2007-08-06 15:18:53 UTC (rev 1089) @@ -668,33 +668,6 @@ return $ret; } - - function incMeta($group, $subgroup, $leaf) - { - $ret = $this->_container->incMeta($group, $subgroup, $leaf); - - if ($this->_usememorycache) - { - // store the modifications in the cache - if (isset($this->_cache[$group]['value']) && - !in_array($subgroup, $this->_cache[$group]['value'])) - { - $this->_cache[$group]['value'][] = $subgroup; - $this->_cache[$group]['timestamp'][] = time(); - } - if (isset($this->_cache[$group]['childs'][$subgroup]['value']) && - !in_array($leaf, $this->_cache[$group]['childs'][$subgroup]['value'])) - { - $this->_cache[$group]['childs'][$subgroup]['value'][] = $leaf; - $this->_cache[$group]['childs'][$subgroup]['timestamp'][] = time(); - } - $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = array($leafvalue); - $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = array(time()); - } - - return $ret; - } - /** * Increment a counter identified by the following path : group / subgroup / leaf * Notice: this step must be atomic in order to avoid multithread problem (don't forget to use locking features) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-08 03:39:03
|
Revision: 1098 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1098&view=rev Author: gpinzone Date: 2007-08-07 20:39:04 -0700 (Tue, 07 Aug 2007) Log Message: ----------- Cleanup of user commands on exit. Modified Paths: -------------- trunk/src/pfccontainer.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-08 02:11:56 UTC (rev 1097) +++ trunk/src/pfccontainer.class.php 2007-08-08 03:39:04 UTC (rev 1098) @@ -197,6 +197,10 @@ $this->rmMeta('nickid-to-metadata', $nickid); } + // remove users commands in queue + $this->rmMeta("nickid-to-cmdtoplay", $nickid); + $this->rmMeta("nickid-to-cmdtoplayid", $nickid); + return $deleted_user; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-08-08 07:08:20
|
Revision: 1099 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1099&view=rev Author: kerphi Date: 2007-08-08 00:08:23 -0700 (Wed, 08 Aug 2007) Log Message: ----------- remove users commands in queue when user disconnected from all the channels Modified Paths: -------------- trunk/src/pfccontainer.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-08 03:39:04 UTC (rev 1098) +++ trunk/src/pfccontainer.class.php 2007-08-08 07:08:23 UTC (rev 1099) @@ -195,12 +195,11 @@ $this->rmMeta('metadata-to-nickid', 'nick', $this->encode($this->getNickname($nickid))); // remove disconnected nickname metadata $this->rmMeta('nickid-to-metadata', $nickid); + // remove users commands in queue + $this->rmMeta("nickid-to-cmdtoplay", $nickid); + $this->rmMeta("nickid-to-cmdtoplayid", $nickid); } - // remove users commands in queue - $this->rmMeta("nickid-to-cmdtoplay", $nickid); - $this->rmMeta("nickid-to-cmdtoplayid", $nickid); - return $deleted_user; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-09-06 17:51:17
|
Revision: 1182 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1182&view=rev Author: kerphi Date: 2007-09-06 10:51:11 -0700 (Thu, 06 Sep 2007) Log Message: ----------- Optimization when reading new messages: do not use readdir() anymore, just trust content of messages file index Modified Paths: -------------- trunk/src/pfccontainer.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-09-06 17:09:01 UTC (rev 1181) +++ trunk/src/pfccontainer.class.php 2007-09-06 17:51:11 UTC (rev 1182) @@ -413,24 +413,10 @@ $c =& pfcGlobalConfig::Instance(); if ($chan == NULL) $chan = 'SERVER'; - // read new messages id - $new_msgid_list = array(); - $new_from_id = $from_id; - $msgid_list = $this->getMeta("channelid-to-msg", $this->encode($chan)); - for($i = 0; $i<count($msgid_list["value"]); $i++) - { - $msgidtmp = $msgid_list["value"][$i]; - - if ($msgidtmp > $from_id) - { - if ($msgidtmp > $new_from_id) $new_from_id = $msgidtmp; - $new_msgid_list[] = $msgidtmp; - } - } - - // read messages content and parse content + // read new messages content + parse content + $new_from_id = $this->getLastId($chan); $datalist = array(); - foreach ( $new_msgid_list as $mid ) + for ( $mid = $from_id; $mid <= $new_from_id; $mid++ ) { $line = $this->getMeta("channelid-to-msg", $this->encode($chan), $mid, true); $line = $line["value"][0]; @@ -446,11 +432,9 @@ $data["param"] = pfc_make_hyperlink($formated_line[4]); $datalist[$data["id"]] = $data; } - } - ksort($datalist); - + } return array("data" => $datalist, - "new_from_id" => $new_from_id ); + "new_from_id" => $new_from_id+1 ); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |