potatolondon/django-mediagenerator — pull request #11 by msiedlarek (2012-09-14 09:18:38+00:00)
Title: Reasonable behavior in development mode

Fixes #9 and possibly other issues.

It is a known fact that django-mediagenerator in its current state is quite annoying to use in development mode when serious amounts of static files are used throughout a project, due to performance problems.

The reason of those performance project is refreshing static names, namely recursive scanning over all static directories performed by development middleware on **each single request**.

This was a serious problem for my project, so I fixed it in a way I considered reasonable. Oh, and there's a caveat - my fix introduces a dependency to well-known [watchdog package](http://packages.python.org/watchdog/).

What middleware now does is it scans the directories on a first request and sets up a watchdog event handler, to rescan the directories when needed, namely when a file or directory is created/moved/deleted wherever in the static file trees.

*And there's a bonus.* As now middleware is using a threading lock to protect `_refresh_dev_names()` from concurrent calls it seems to fix (no guarantee) thread-safety problems on Django built-in server, which as of version 1.4 is threaded.

I hope additional dependency will be considered worth it.