LocDB LocTitles

This is about a deeper aspect of class LocTitle.

Sorting
Whenever titles have to be sorted, let the DB do. Unicode support for PHP will come up in PHP 6, but there seem to be delays so that PHP 6 can not be expected to be released before beginning of 2009.

Even if Unicode in PHP would work, it's still a question what's more efficient. Sorting Titles means to sort with callback function. This takes by factor ~5 more time than the DB needs if there is an additional ORDER BY option in the query. Thus, whenever a DB querey is needed anyway, it's more efficient to let the DB sort.

If we need an extra DB query just for sorting, PHP would be somewhat faster (roughly factor 2), but then there still remains the Unicode problem.

The sorting strategy has a strong impact on what and how location data can be cached.

Multiple Memcache calls vs. Single DB load
Getting cached data from Memcache is not for free. Tests have turned out that many memcache calls instead of one DB load are less efficient. For example, getting the names of sublocations with one DB load is more efficient than asking each location one by one for its name, even if the names come out of the memcache.

Preferred Titles and Fix-Language Titles
Each location has a set of alias titles, one for each language. Specialy on the input wiki, the displayed titles has to be selected according to the wiki's and user's preferrences. That's what we call the "preferred title". On language version wikis, in opposite, the language of the title is usualy the wiki's content language. Locations that don't have a title in this language are usualy out of interest and need not to be listed.

As long as there are single locations, simply memcache the set of alias titles and select the preferred or fix-language title from it.

If we have to handle sets of locations, e.g. (recursive) sub-locations, a differnt caching strategy seems to be more efficient.

Whenever we need to deal with preferred titles, it seems to be the best to cache sets of alias IDs ( field localias.las_id in the DB), one for each language. Like this:

The set of preferred alias IDs can be built efficiently by array addition:

Finaly, SELECT the dbkeys corresponding to the alias IDs from the DB and let the DB sort the dbkeys alphabeticaly.

If we only need fix-language titles, it is sufficient just to know the location IDs, no matter whether the location realy has an alias title for the language in question or not. The alphabeticaly sorted list of titles can by SELECTed by a simply join of the location table and the alias (localias) table.