newsapps/django-boundaryservice — pull request #40 by palewire (2013-05-01 05:01:56+00:00)
Title: Refactored loadshapefiles for speed

I was able to drastically increase the speed of the ``loadshapefiles`` management comment by changing a few small things.

1. The ``len(layer)`` to set the ``count`` attribute of new ``BoundarySet`` objects takes a really long time, to my surprise. Just initializing the set with zero in that field and then letting the count be calculated via SQL after everything's in the database is way faster. Since the app is already doing that recalculation anyway, you don't have to add any code.

2. A modification of the process that guarantees a unique slug that doesn't require pulling of every single slug out of the database and into memory with each save call. I replaced the existing process with SQL count queries that I suspect are faster.

The result is that time it takes my laptop to load a SHP file with ~3000 features dropped from more than 8 hours to less than 3 minutes.