Patch lean grids

Here's a shot at basing what grids get exported dependent on the tiles routine. Rather than doing one query for all grids, which results in lots of empty grids in tilesets where there are a lot of areas without tiles, this version runs a separate write_grid function each time a tile is created. This creates many more queries, but I didn't see much if any decrease in exporting performance at the 50k-100k tile range. And any slowdown is more than made up for by not having to export and upload empty tiles.