0.11beta6 Released!

Project Announcements. This is read-only, as in... not for problems/bugs/feature request.
Piratos

Re: 0.11beta6 Released!

Post by Piratos »

Some small changes as example (content.inc.php)

Code: Select all

        function GetDefaultContent()
	{
		global $gCms;
		$db = &$gCms->db;

		$result = -1;

		$query = "SELECT content_id FROM ".cms_db_prefix()."content WHERE default_content = 1";
		$row = $db->GetRow($query);
		if ($row)
		{
			$result = $row['content_id'];
		}
		else
		{
			#Just get something...
			$query = "SELECT content_id FROM ".cms_db_prefix()."content";
			$row = $db->GetRow($query);
			if ($row)
			{
				$result = $row['content_id'];
			}
		}

		return $result;
	}


	// function to get the id of the default page
	function GetDefaultPageID()
	{
	  global $gCms;
	  $db = &$gCms->db;

	  $query = "SELECT * FROM ".cms_db_prefix()."content WHERE default_content = ?";
	  $row = $db->GetRow($query, array(1));
	  if ( !$row ) return false;
	  return $row['content_id'];
	}


	// function to map an alias to a page id
	// returns false if nothing cound be found.
	function GetPageIDFromAlias( $alias )
	{
	  global $gCms;
	  $db = &$gCms->db;

	  if (is_numeric($alias) && strpos($alias,'.') == FALSE && strpos($alias,',') == FALSE)
	    {
	      return $alias;
	    }

	  $params = array($alias);
	  $query = "SELECT * FROM ".cms_db_prefix()."content WHERE content_alias = ?";
	  $row = $db->GetRow($query, $params);

	  if ( !$row)return false;
	  return $row['content_id'];
	}
	

	// function to map an alias to a page id
	// returns false if nothing cound be found.
	function GetPageAliasFromID( $id )
	{
	  global $gCms;
	  $db = &$gCms->db;

	  if (!is_numeric($alias) && strpos($alias,'.') == TRUE && strpos($alias,',') == TRUE)
	    {
	      return $id;
	    }

	  $params = array($id);
	  $query = "SELECT * FROM ".cms_db_prefix()."content WHERE content_id = ?";
	  $row = $db->GetRow($query, $params);

	  if ( !$row)return false;
	  return $row['content_alias'];
	}


        	function CheckAliasError($alias, $content_id = -1)
	{
		global $gCms;
		$db = &$gCms->db;

		$error = FALSE;

		if (preg_match('/^\d+$/', $alias))
		{
			$error = lang('aliasnotaninteger');
		}
		else if (!preg_match('/^[\-\_\w]+$/', $alias))
		{
			$error = lang('aliasmustbelettersandnumbers');
		}
		else
		{
			$params = array($alias);
			$query = "SELECT * FROM ".cms_db_prefix()."content WHERE content_alias = ?";
			if ($content_id > -1)
			{
				$query = " AND content_id != ?";
				array_push($params, $content_id);
			}
			$dbresult = $db->GetRow($query, $params);

			if ($dbresult) $error = lang('aliasalreadyused');

		}

		return $error;
	}
But the biggest problem is your ListContentTypes.

If i use  admin listcontents with 390 pages this functions has a loop of total 62.790  !!!!

That it is what makes it so slow !!!
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: 0.11beta6 Released!

Post by Ted »

Piratos.  Thank you!  This is exactly the kind of input I need in order to help locate these problems.  I'm going to put in GetRow as much as I can (which does make total sense), and I'll push the output of ListContentTypes into a cached (and referenced) variable so that it only needs to look once.

Thanks again!
melix

Re: 0.11beta6 Released!

Post by melix »

When I made my own content list view (still available into this forum), I had this performance issue coming up. One thing that could really make your algorithms more simple is to tweak indexes. For example, the GetAllContent method returns a simple array, while it could return an indexed one, for exemple where the index would be the id of the page, its alias, ... This makes things easier. Thanks to references, you could also return a more complex data structure that allows multiple indexes (id, alias, hierarchy) which would make algorithms less complex (in terms of algorithmic complexity).

For example, in the listcontent.php page (always this one ;)), you definitely miss a hierarchical data structure. To be able to detect what can be moved up or down, you have to create embedded loops, which are awful in terms of complexity.

Maybe you could take a look at these tweaks ;)
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: 0.11beta6 Released!

Post by Ted »

Yeah, I agree with that.  The issue was that I didn't realize that a hash will act like an array in php.  Meaning that items stay in the same order they're put in.  In most other languages, a hash will not keep it's order.  Since I have it coming through in hierarchial order, I wanted to be sure it stayed that way.  Now I can probably add the id as a key and it wouldn't mess up anything...

I'll have to go back and look at your code.

Thanks
Piratos

Re: 0.11beta6 Released!

Post by Piratos »

Here another sample to spare memory (page.functions.php  load_all_permissions):

The normal way produced 2444 Bytes in output:

Code: Select all

ADORecordSet_mysql Object ( [databaseType] => mysql [canSeek] => 1 [dataProvider] => native [fields] => Array ( [permission_name] => Add Pages ) [blobSize] => 100 [sql] => SELECT DISTINCT permission_name FROM cms_user_groups ug INNER JOIN cms_group_perms gp ON gp.group_id = ug.group_id INNER JOIN cms_permissions p ON p.permission_id = gp.permission_id WHERE ug.user_id = '1' [EOF] => [emptyTimeStamp] =>   [emptyDate] =>   [debug] => [timeCreated] => 0 [bind] => [fetchMode] => 1 [connection] => ADODB_mysql Object ( [databaseType] => mysql [dataProvider] => mysql [hasInsertID] => 1 [hasAffectedRows] => 1 [metaTablesSQL] => SHOW TABLES [metaColumnsSQL] => SHOW COLUMNS FROM %s [fmtTimeStamp] => Y-m-d H:i:s [hasLimit] => 1 [hasMoveFirst] => 1 [hasGenID] => 1 [isoDates] => 1 [sysDate] => CURDATE() [sysTimeStamp] => NOW() [hasTransactions] => [forceNewConnect] => [poorAffectedRows] => 1 [clientFlags] => 0 [substr] => substring [nameQuote] => ` [_genIDSQL] => update %s set id=LAST_INSERT_ID(id+1); [_genSeqSQL] => create table %s (id int not null) [_genSeq2SQL] => insert into %s values (%s) [_dropSeqSQL] => drop table %s [database] => ctest [host] => localhost [user] => root [password] => 1030410 [debug] => [maxblobsize] => 262144 [concat_operator] => + [length] => length [random] => rand() [upperCase] => upper [fmtDate] => 'Y-m-d' [true] => 1 [false] => 0 [replaceQuote] => \' [charSet] => [metaDatabasesSQL] => [uniqueOrderBy] => [emptyDate] =>   [emptyTimeStamp] =>   [lastInsID] => [hasTop] => [readOnly] => [genID] => 0 [raiseErrorFn] => [cacheSecs] => 3600 [arrayClass] => ADORecordSet_array [noNullStrings] => [numCacheHits] => 0 [numCacheMisses] => 0 [pageExecuteCountRows] => 1 [uniqueSort] => [leftOuter] => [rightOuter] => [ansiOuter] => [autoRollback] => [fnExecute] => count_sql_execs [fnCacheExecute] => [blobEncodeType] => [rsPrefix] => ADORecordSet_ [autoCommit] => 1 [transOff] => 0 [transCnt] => 0 [fetchMode] => 2 [_oldRaiseFn] => [_transOK] => [_connectionID] => Resource id #56 [_errorMsg] => [_errorCode] => [_queryID] => Resource id #149 [_isPersistentConnection] => 1 [_bindInputArray] => [_evalAll] => [_affected] => [_logsql] => ) [_numOfRows] => 30 [_numOfFields] => 1 [_queryID] => Resource id #148 [_currentRow] => 0 [_closed] => [_inited] => 1 [_obj] => [_names] => [_currentPage] => -1 [_atFirstPage] => [_atLastPage] => [_lastPageNo] => -1 [_maxRecordCount] => 0 [datetime] => [adodbFetchMode] => 2 )



The getall - way produced 1675 Bytes in output:

Code: Select all

Array ( [0] => Array ( [permission_name] => Add Pages ) [1] => Array ( [permission_name] => Add Groups ) [2] => Array ( [permission_name] => Add Templates ) [3] => Array ( [permission_name] => Add Users ) [4] => Array ( [permission_name] => Modify Any Page ) [5] => Array ( [permission_name] => Modify Groups ) [6] => Array ( [permission_name] => Modify Group Assignments ) [7] => Array ( [permission_name] => Modify Permissions ) [8] => Array ( [permission_name] => Modify Templates ) [9] => Array ( [permission_name] => Modify Users ) [10] => Array ( [permission_name] => Remove Pages ) [11] => Array ( [permission_name] => Remove Groups ) [12] => Array ( [permission_name] => Remove Templates ) [13] => Array ( [permission_name] => Remove Users ) [14] => Array ( [permission_name] => Modify Modules ) [15] => Array ( [permission_name] => Modify Files ) [16] => Array ( [permission_name] => Modify Site Preferences ) [17] => Array ( [permission_name] => Modify Stylesheets ) [18] => Array ( [permission_name] => Add Stylesheets ) [19] => Array ( [permission_name] => Remove Stylesheets ) [20] => Array ( [permission_name] => Add Stylesheet Assoc ) [21] => Array ( [permission_name] => Modify Stylesheet Assoc ) [22] => Array ( [permission_name] => Remove Stylesheet Assoc ) [23] => Array ( [permission_name] => Modify Code Blocks ) [24] => Array ( [permission_name] => Clear Admin Log ) [25] => Array ( [permission_name] => Add Html Blobs ) [26] => Array ( [permission_name] => Modify Html Blobs ) [27] => Array ( [permission_name] => Remove Html Blobs ) [28] => Array ( [permission_name] => Create Backup Sets ) [29] => Array ( [permission_name] => Restore Backup Sets ) )
cyberman

Re: 0.11beta6 Released!

Post by cyberman »

wishy wrote: However, I have a feeling that they're ADODB related for the most part, which kind of scares me.
Perhaps another chance for AdoDB light I've told you long time ago ?
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: 0.11beta6 Released!

Post by Ted »

Yeah, I'm probably going to look into that again.  Same thing, though, is that we lose the database creation functions.  Which means that we need to rewrite how the installer and especially, how modules install their tables.

However, if it would prove to fix some of these issues, it might be worth looking into for a post 1.0 milestone.
Piratos

Re: 0.11beta6 Released!

Post by Piratos »

Which means that we need to rewrite how the installer and especially, how modules install their tables.
Nearly nobody is using postgrsql. Why don't you change to mysql direkt - it is 2 - 3 faster as adodb.
melix

Re: 0.11beta6 Released!

Post by melix »

I disagree : ADODB provides an "objective" view of database, which is much better than simple functions. Moreover, it provides a set of convenient methods (like Execute()) which allows to externalize security (thanks to usage of "?" in queries). This is worth an overhead, which I'm quite sure can be tuned up.

(maybe we should continue this discussion in the developer section of the forum ?)
Piratos

Re: 0.11beta6 Released!

Post by Piratos »

The advantage of adodb is given if you write software to use several databases.

for this adodb is a layer system. if nearly nobody is using postgrsql it cost only time and memory.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: 0.11beta6 Released!

Post by Ted »

Well, the reason I keep holding on to this is because I know that sqlite is going to become more and more important as PHP5 starts making it's way onto all of the web hosts out there.

The idea that we can get this thing to install without having users have to setup a database would be a huge win.

So, to me, some kind of abstraction should be there.  Though, if it was thinner than adodb, I wouldn't mind.  It does have some decent overhead.
Piratos

Re: 0.11beta6 Released!

Post by Piratos »

sqlite
Yeah this is great - my own second  commercial cms works with sqlite - wonderfull. it works fine and fast until  2000 pages. above 2000 pages mysql is better.But who has so many pages ??

But now we have adodb and here another example to make it faster:

Code: Select all

 function load_all_permissions($userid)
{
	global $gCms;
	$db = &$gCms->db;
	$variables = &$gCms->variables;

	$perms = array();

	$query = "SELECT DISTINCT permission_name FROM ".cms_db_prefix()."user_groups ug INNER JOIN ".cms_db_prefix()."group_perms gp ON gp.group_id = ug.group_id INNER JOIN ".cms_db_prefix()."permissions p ON p.permission_id = gp.permission_id WHERE ug.user_id = ?";
	$result = &$db->Execute($query, array($userid));
	while (!$result->EOF)
	{
          array_push($perms, $result->fields['permission_name']);
          $result->MoveNext();
	}
	$variables['userperms'] = $perms;
}
It takes by viewing the default page (1 of 390) an advantage of 0,02 seconds - many for this small function. you must see - you have many of this .
Piratos

Re: 0.11beta6 Released!

Post by Piratos »

Look at the pictures from here  http://forum.cmsmadesimple.org/index.ph ... .html  (CSS - Speed Menu).

The interesting point is the need of memory with and without eaccellerator.

Without nearly 7 MB , with nearly 1 MB  (390 pages).
idcarlos

Re: 0.11beta6 Released!

Post by idcarlos »

wishy wrote: I am open to other options on an abstraction library that is like ADODB, though I would really miss the table creation functions and it would make installation (of the core and modules) much more difficult for different database platforms.
Please test http://adodblite.sourceforge.net/index.php
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: 0.11beta6 Released!

Post by Ted »

Hmmm....

So adodb lite has added Data Dictionary functions and also the date functions.  Very interesting.  As soon as I get 0.11 out, I'll start playing with it again.
Post Reply

Return to “Announcements”