GraphViz & SVG frustration

I thought I’d do a little warm-up hack for HackDay, so I wrote a little thing to interrogate the backnetwork API and build a network diagram of all the relations using GraphViz. It started out looking quite promising, but I soon discovered that lots of GraphViz features just don’t work very well (even simple stuff like putting labels in boxes), and also that common SVG implementations suck. Firefox’ SVG rendering is just awful – no anti-aliasing, lots of misdrawing, all text defaulting to 18px Courier bold and worse. WebKit’s nightlies are in a different league in terms of accuracy and rendering quality, but since scrolling is broken, large diagrams are kind of hard to display. GraphViz’s layout mechanisms are pretty cool (if rather unpredictable), but the errors it makes for labelling stuff just makes it unusable. Its output directly to PNG was worse than the SVG renderings.

This was my first attempt at using both GraphViz and SVG, and I have to say I’m massively underwhelmed. I hope that I’m using a bad version, or there’s some issue with my font configs as it really should be possible to get decent output from what I’ve gathered.

Update
Thanks to Bruno Pedro, I have something to compare against, and now something to point the finger at… It appears that the OSX version of GraphViz from fink is a waste of space, and simply doesn’t support some vital features. Secondly, it’s clear that Mac Firefox’ SVG rendering is totally broken, but the windows version works ok (in Parallels). Thanks Bruno!

CakePHP’s invisible query cache

I just wanted to document something that was driving me nuts in Cake PHP.

I do a simple find on a model:

$thing = $this->Model->find(array('id' => 123), NULL, NULL, 1);

Then later on, I make the same query again. Only the first query appears in the SQL debug output. Why call it again? Well, I’ve made some manual queries in between the calls using SQL that is inconvenient to emulate in Cake functions, in particular INSERT IGNORE. It turns out that Cake has a largely undocumented query cache, but Cake has no idea that its cache is dirty because of the manual queries. The _clearCache function is not yet implemented for the query cache, so the only choice is to disable it before the first query, and you can do that during a single instantiation by saying:

$this->Model->cacheQueries = false;

Note that the query has 1 level of recursion, which means that all the sub-queries are also cached. Setting cacheQueries to false on this one model means that all queries through it don’t get cached, including those that may be in other models via relationships.