Tuesday 20 February 2007

PHP_CodeSniffer 0.4.0 (beta) released

I released version 0.4.0 of PHP_CodeSniffer yesterday. Version 0.4.0 is mainly a bug-fix release. All but one of the bugs found were in the Squiz coding standards, which is not surprising as they are the newest standards and are being used by the MySource 4.0 team on a daily basis.

There are two minor new features in version 0.4.0 also.

The first is the wrapping of the error and warning messages in PHP_CodeSniffer's output. I wrote about that feature here.

The other change allows for coding standard names to be specified in whatever case you desire. Previously, PHP_CodeSniffer required the case of the supplied standard name and the standard directory to match exactly. Now, everything is compared in lowercase, so it doesn't matter how you specify it. For example, all these commands will check the file testfile.php against the PEAR coding standards:

phpcs --standard=PEAR testfile.php
phpcs --standard=Pear testfile.php
phpcs --standard=pear testfile.php
phpcs --standard=pEaR testfile.php
You can view the full changelog and download the release here.

Friday 16 February 2007

A better way to cascade in MySource 4.0

When the MySource Matrix permission system was first being planned, we tried a number of different database schemas to allow permissions to inherit to assets from multiple parents. The biggest problem was the time taken to check if a permission exists (eg. read access). With permission queries being some of the most common, they really needed to be as fast as possible.

The solution we came up with was a pretty basic one; cascade permissions to all child assets when setting them. So, for example, when you grant public read access on a Site asset, we run a HIPO job to set that same permission on every asset within the site. This allows us to check if any particular asset has public read access without having to determine its position in the tree. Instead of waiting for slow queries on the frontend, we made the backend processing slower.

There are two main problems with this approach. The first is that the data storage requirements are significantly greater than if we inherited permissions. The second problem is that cascading takes a very long time.

We just finished the planning of the Roles system for MySource 4.0. The roles system replaces the Permissions system in MySource Matrix, but requires the same general concept. We reevaluated the storage of permission assignments in MySource Matrix to see if we could remove the need for cascading role assignments.

Long story short; we couldn't. We still need to have a table with all the role assignments for every asset so we can quickly access role assignments for specific assets, and so that we can join the table to add permission checks to other queries. So we turned our attention to how we cascade assignments and looked for ways to make the process faster.

Here, we did succeed.

In MySource Matrix, we first get a list of all assets under the asset we are setting permissions on. Then we loop through each asset and assign the permission. A database query is executed for each of these assets to add the permission assignment. In reality, a lot more database queries are executed to load the asset and check its current assignments. HIPO thresholds are used to process more than one asset at a time, and the Squiz Server is used to process all assets in one go. Both thresholds and the Squiz Server make the process faster, but they don't reduce the number of queries executed.

In MySource 4.0, we have always wanted to get rid of the need for HIPO jobs and the Squiz Server. We are pretty sure we don't need the Squiz Server any more, but we will still need a HIPO job of some sort. The big difference are the thresholds. Whereas in MySource Matrix you could potentially process up to 50 assets at a time, MySource 4.0 thresholds will be more like 50,000. So even with HIPO jobs, you'll probably never see them.

We have written some new queries that will allow us to process different levels of the tree in one go, or multiple levels if they fit within the threshold. The reason we can increase the number of assets processed at once so much is because we no longer load assets and insert rows one by one. Instead, our new queries can look at the tree, select an entire level, and insert several thousand rows at once. These queries can also take granted and denied permissions into account, so you can't apply public read access where it is already denied (eg. a members only area).

We tested our theory yesterday with a sample of 44,000 assets from a MySource Matrix system. The goal was to select a entire section of a tree and insert new role assignments for all assets that did not currently have that role set. Here are the results:

# INSERT INTO asset_role_assignments (assetid, userid, roleid, granted)
# SELECT distinct l.minorid AS assetid, '90211' AS userid, '1234' AS roleid, 1 AS granted FROM
# sq_ast_lnk l INNER JOIN sq_ast_lnk_tree t ON t.linkid = l.linkid
# WHERE
# t.treeid like '00010002000D00030000%'
# AND NOT EXISTS (
# SELECT 1 FROM
# sq_ast_perm p
# WHERE
# p.assetid = l.minorid
# AND p.userid = '90211'
# AND p.permission = 2
# );
INSERT 0 44041
Time: 2441.133 ms
This test was run on a dedicated database server using PostgreSQL 8.2. Over 44,000 entries were inserted in about 2.4 seconds. We calculated that processing 44,000 assets in MySource Matrix would take around 6 hours. The other thing to consider is that a Standard Page in MySource Matrix is actually 4 assets, whereas it is only 1 asset in MySource 4.0. So these figures actually tell us that MySource 4.0 can process 44,000 pages in 2.4 seconds whereas MySource Matrix can process 11,000 in 6 hours.

We have now started development of the Roles system, so it wont be too long until we can start trying this out with some real data. The results so far do look very promising though.

Monday 5 February 2007

MySource Matrix 3.12.1, 3.10.6 released

Squiz.net today made two new point releases of the MySource Matrix Open Source Content Management System available to the public; versions 3.12.1 and 3.10.6.

Version 3.12.1 is the latest release on the most recent stable branch of MySource Matrix and provides 28 bugs fixes as well as 3 new feature improvements. The LDAP Bridge now checks for PHP LDAP support, the "Back To" bar in the admin interface now wraps across 2 lines, and the asset lineage design area now has config options for print and cache in the admin interface.

Version 3.10.6 is a bug-fix only release, providing 21 fixes to bugs previously reported in 3.10.5.

The GPL editions of both versions are now available for you to download from the MySource Matrix download page. A full list of changes within each version are provided with the downloads.