Solved the problem with UHS

See https://bugs.launchpad.net/oq-engine/+bug/1362649. I also did some cleanup on the hazard map generation mechanism to be consistent with the rest of the code. The tests are green: https://ci.openquake.org/job/zdevel_oq-engine/635
Where am I using the magic number? There is a line `writer.CacheInserter(models.HazardCurveData, max_cache_size=10000)` which I think is clear enough.